C+ Aptitude Exam: Quiz!

Approved & Edited by ProProfs Editorial Team
At ProProfs Quizzes, our dedicated in-house team of experts takes pride in their work. With a sharp eye for detail, they meticulously review each quiz. This ensures that every quiz, taken by over 100 million users, meets our standards of accuracy, clarity, and engagement.
| Written by Soundarya
S
Soundarya
Community Contributor
Quizzes Created: 1 | Total Attempts: 114
Questions: 40 | Attempts: 114

Settings

.

• 1.

Which of the following is the correct order of evaluation for the below expression? z = x + y * z / 4 % 2 - 1

• A.

* / % + - =

• B.

= * / % + -

• C.

/ * % - + =

• D.

* % / - + =

A. * / % + - =
Explanation
The correct order of evaluation for the given expression is as follows: First, the multiplication operation is performed (y * z). Then, the division operation is performed (y * z / 4). Next, the modulo operation is performed (y * z / 4 % 2). After that, the addition operation is performed (x + y * z / 4 % 2). Finally, the subtraction operation is performed (x + y * z / 4 % 2 - 1).

Rate this question:

• 2.

Which of the following correctly shows the hierarchy of arithmetic operations in C?

• A.

/ + * -

• B.

* - / +

• C.

+ - / *

• D.

/ * + -

D. / * + -
Explanation
The correct answer shows the hierarchy of arithmetic operations in C. In C, the multiplication and division operations have higher precedence than addition and subtraction. Therefore, the correct hierarchy is division, multiplication, addition, and subtraction. The answer / * + - correctly represents this hierarchy.

Rate this question:

• 3.

In which order do the following gets evaluated 1. Relational 2. Arithmetic 3. Logical 4. Assignment

• A.

2134

• B.

1234

• C.

4321

• D.

3214

A. 2134
Explanation
The given answer, 2134, suggests that the order of evaluation is as follows: Relational (2), Arithmetic (1), Logical (3), and Assignment (4). This means that relational operations are evaluated first, followed by arithmetic operations, then logical operations, and finally assignment operations.

Rate this question:

• 4.

Which of the following is the correct usage of conditional operators used in C?

• A.

A>b ? c=30 : c=40;

• B.

A>b ? c=30;

• C.

Max = a>b ? a>c?a:c:b>c?b:c

• D.

Return (a>b)?(a:b)

C. Max = a>b ? a>c?a:c:b>c?b:c
Explanation
The correct usage of conditional operators in C is shown in the answer "max = a>b ? a>c?a:c:b>c?b:c". This expression uses nested conditional operators to determine the maximum value among three variables a, b, and c. It first checks if a is greater than b, and if true, it checks if a is greater than c. If both conditions are true, the value of a is assigned to max. If the first condition is true but the second is false, the value of c is assigned to max. If the first condition is false, it checks if b is greater than c. If true, the value of b is assigned to max. If false, the value of c is assigned to max.

Rate this question:

• 5.

What will the function rewind() do?

• A.

Reposition the file pointer to a character reverse.

• B.

Reposition the file pointer stream to end of file

• C.

Reposition the file pointer to beginning of that line

• D.

Reposition the file pointer to beginning of file.

D. Reposition the file pointer to beginning of file.
Explanation
The function rewind() is used to reposition the file pointer to the beginning of the file. This means that after calling the rewind() function, any subsequent read or write operations on the file will start from the beginning of the file.

Rate this question:

• 6.

Input/output function prototypes and macros are defined in which header file?

• A.

Conio.h

• B.

Stdlib.h

• C.

Stdio.h

• D.

Dos.h

C. Stdio.h
Explanation
The correct answer is stdio.h. This header file in C programming language contains the definitions of input/output functions such as printf, scanf, and file operations. It is used to handle input and output operations in the program.

Rate this question:

• 7.

Which standard library function will you use to find the last occurrence of a character in a string in C?

• A.

Strnchar()

• B.

Strchar()

• C.

Strrchar()

• D.

Strrchr()

D. Strrchr()
Explanation
The strrchr() function is the correct answer because it is a standard library function in C that is used to find the last occurrence of a character in a string. It takes two arguments - the string in which to search for the character, and the character to search for. The function returns a pointer to the last occurrence of the character in the string, or NULL if the character is not found. Therefore, strrchr() is the appropriate function to use in this scenario.

Rate this question:

• 8.

What is stderr?

• A.

Standard error

• B.

Standard error types

• C.

Standard error streams

• D.

Standard error definitions

C. Standard error streams
Explanation
Stderr stands for standard error streams. In computer programming, stderr is a standard stream where error messages and diagnostic information are typically sent. It is separate from the standard output stream (stdout) and is used to display error messages and warnings to the user. By using stderr, developers can differentiate between regular output and error messages, making it easier to identify and troubleshoot issues in the program.

Rate this question:

• 9.

What is the purpose of fflush() function?

• A.

Flushes all streams and specified streams.

• B.

Flushes only specified stream

• C.

Flushes input/output buffer

• D.

Flushes file buffer

A. Flushes all streams and specified streams.
Explanation
The purpose of the fflush() function is to flush the output buffer of a stream. When data is written to a stream, it is not immediately sent to the destination, but instead stored in a buffer. Flushing the buffer means that the data is forced to be written to the destination immediately. The fflush() function can be used to flush all streams or only specific streams, depending on the parameters passed to it.

Rate this question:

• 10.

What will the function randomize() do in Turbo C under DOS?

• A.

Returns a random number

• B.

Returns a random number generator in the specified range.

• C.

Returns a random number generator with a random value based on time

• D.

Return a random number with a given seed value

C. Returns a random number generator with a random value based on time
Explanation
The function randomize() in Turbo C under DOS will return a random number generator with a random value based on time. This means that each time the function is called, it will generate a different random number. The random value is based on the current time, which ensures that the generated numbers are unpredictable and appear random.

Rate this question:

• 11.

In which numbering system can the binary number 1011011111000101 be easily converted to?

• A.

Decimal system

• B.

• C.

Octal system

• D.

No need to convert

Explanation
The binary number 1011011111000101 can be easily converted to the hexadecimal system. In the hexadecimal system, each digit represents four bits, making it a convenient choice for converting binary numbers. The binary number can be divided into groups of four bits, and each group can be replaced with its corresponding hexadecimal digit. In this case, the binary number can be divided into 1011 0111 1100 0101, which can be converted to the hexadecimal number B7C5.

Rate this question:

• 12.

Which bitwise operator is suitable for turning on a particular bit in a number?

• A.

&& operator

• B.

& operator

• C.

|| operator

• D.

| operator

D. | operator
Explanation
The | operator is suitable for turning on a particular bit in a number. This operator performs a bitwise OR operation between two operands, resulting in a number where the bit is turned on if it is turned on in either of the operands. Therefore, by using the | operator with the desired bit set to 1 and the rest set to 0, the bit can be turned on in the number.

Rate this question:

• 13.

Which header file should be included to use functions like malloc() and calloc()?

• A.

Memory.h

• B.

Stdlib.h

• C.

String.h

• D.

Dos.h

B. Stdlib.h
Explanation
To use functions like malloc() and calloc(), the header file that needs to be included is stdlib.h. This header file provides the necessary declarations and definitions for memory allocation and deallocation functions in the C programming language. It also includes other important functions such as atoi() and exit(). Therefore, including stdlib.h allows the program to access these functions and perform dynamic memory allocation.

Rate this question:

• 14.

What function should be used to free the memory allocated by calloc() ?

• A.

Dealloc();

• B.

Malloc(variable_name, 0)

• C.

Free();

• D.

Memalloc(variable_name, 0)

C. Free();
Explanation
The function that should be used to free the memory allocated by calloc() is free(). This function is used to deallocate the memory previously allocated by calloc(), malloc(), or realloc(). By calling free(), the memory is released and can be reused for other purposes.

Rate this question:

• 15.

What are the different types of real data types in C?

• A.

Float, double

• B.

Short int, double, long int

• C.

Float, double, long double

• D.

Double, long int, float

C. Float, double, long double
Explanation
The correct answer is float, double, long double. These are the different types of real data types in C. A float is a single-precision floating-point number, a double is a double-precision floating-point number, and a long double is an extended-precision floating-point number. These data types are used to represent decimal numbers with varying degrees of precision and range.

Rate this question:

• 16.

What will you do to treat the constant 3.14 as a long double?

• A.

Use 3.14LD

• B.

Use 3.14L

• C.

Use 3.14DL

• D.

Use 3.14LF

B. Use 3.14L
Explanation
To treat the constant 3.14 as a long double, we need to append the suffix "L" to the constant. This suffix indicates that the constant should be treated as a long double type. Therefore, the correct answer is to use 3.14L.

Rate this question:

• 17.

We want to round off x, a float, to an int value, The correct way to do is

• A.

Y = (int)(x + 0.5)

• B.

Y = int(x + 0.5)

• C.

Y = (int)x + 0.5

• D.

Y = (int)((int)x + 0.5)

A. Y = (int)(x + 0.5)
Explanation
To round off a float value to the nearest integer, the correct way is to add 0.5 to the float value and then cast it to an int using the (int) function. This will ensure that the float value is rounded up if the decimal part is greater than or equal to 0.5, and rounded down if the decimal part is less than 0.5. So, the correct answer is y = (int)(x + 0.5).

Rate this question:

• 18.

The binary equivalent of 5.375 is

• A.

101.101110111

• B.

101.011

• C.

101011

• D.

None of above

B. 101.011
Explanation
The binary equivalent of a decimal number can be found by converting the integer part and the fractional part separately. The integer part of 5.375 is 5, which is represented in binary as 101. The fractional part is 0.375, which can be converted to binary by multiplying it by 2 repeatedly and taking the integer part of each result. This gives us 0.011. Combining the binary representations of the integer and fractional parts gives us 101.011, which is the binary equivalent of 5.375.

Rate this question:

• 19.

Which of the following function sets first n characters of a string to a given character?

• A.

Strinit()

• B.

Strnset()

• C.

Strset()

• D.

Strcset()

B. Strnset()
Explanation
The function strnset() is used to set the first n characters of a string to a given character. This function allows us to specify the number of characters we want to set and the character we want to set them to. Therefore, strnset() is the correct answer for this question.

Rate this question:

• 20.

If the two strings are identical, then strcmp() function returns

• A.

-1

• B.

1

• C.

0

• D.

Yes

C. 0
Explanation
The strcmp() function is used to compare two strings. If the two strings are identical, strcmp() function returns 0.

Rate this question:

• 21.

Which of the following function is used to find the first occurrence of a given string in another string?

• A.

Strchr()

• B.

Strrchr()

• C.

Strstr()

• D.

Strnset()

C. Strstr()
Explanation
The function strstr() is used to find the first occurrence of a given string within another string. It returns a pointer to the first occurrence of the substring, or NULL if the substring is not found. This function is commonly used in string manipulation and searching algorithms.

Rate this question:

• 22.

Which of the following function is more appropriate for reading in a multi-word string?

• A.

Printf();

• B.

Scanf();

• C.

Gets();

• D.

Puts();

C. Gets();
Explanation
The gets() function is more appropriate for reading in a multi-word string because it allows the user to input a string with spaces. The scanf() function stops reading when it encounters a space, so it is not suitable for reading in a multi-word string. The printf() function is used for printing output, not for reading input. The puts() function is used for printing a string, not for reading input.

Rate this question:

• 23.

How will you print \n on the screen?

• A.

Printf("\n");

• B.

Echo "\\n";

• C.

Printf('\n');

• D.

Printf("\\n");

D. Printf("\\n");
Explanation
The correct answer is printf("\"). This is because the printf function is used in C programming to print text or characters on the screen. In this case, the string "\" is being printed, which represents an HTML line break tag.

Rate this question:

• 24.

Is standard library a part of C language?

• A.

Yes

• B.

No

B. No
Explanation
The standard library is not a part of the C language itself. It is a collection of pre-written functions and libraries that provide commonly used functionality, such as input/output operations, string manipulation, and mathematical operations. These functions are included in the C programming language to make it easier for programmers to perform common tasks without having to write the code from scratch. However, the standard library is not an inherent part of the C language syntax and can be omitted or replaced with custom libraries if desired.

Rate this question:

• 25.

The library function used to find the last occurrence of a character in a string is

• A.

Strnstr()

• B.

Laststr()

• C.

Strrchr()

• D.

Strstr()

C. Strrchr()
Explanation
The strrchr() function is the correct answer because it is a library function used to find the last occurrence of a character in a given string. It takes two arguments - the string in which to search for the character, and the character to search for. The function returns a pointer to the last occurrence of the character in the string, or NULL if the character is not found.

Rate this question:

• 26.

The itoa function can convert an integer in decimal, octal or hexadecimal form to a string.

• A.

Yes

• B.

No

A. Yes
Explanation
The itoa function is a standard library function in C that can be used to convert an integer to a string. It takes two arguments - the integer to be converted and a character array to store the resulting string. The function can convert the integer into a decimal, octal, or hexadecimal form based on the specified base. Therefore, it is capable of converting an integer in decimal, octal, or hexadecimal form to a string.

Rate this question:

• 27.

Scanf() or atoi() function can be used to convert a string like "436" in to integer.

• A.

Yes

• B.

No

A. Yes
Explanation
The scanf() and atoi() functions are commonly used in programming to convert a string representation of a number into an integer. In this case, the string "436" can be converted into the integer 436 using either of these functions. Therefore, the correct answer is "Yes".

Rate this question:

• 28.

What do the following declaration signify?int *ptr[30];

• A.

Ptr is a pointer to an array of 30 integer pointers.

• B.

Ptr is a array of 30 pointers to integers

• C.

Ptr is a array of 30 integer pointers.

• D.

Ptr is a array 30 pointers

B. Ptr is a array of 30 pointers to integers
Explanation
The declaration "int *ptr[30]" signifies that ptr is an array of 30 pointers to integers. This means that ptr can hold the memory addresses of 30 integer variables.

Rate this question:

• 29.

What do the following declaration signify?char *arr[10];

• A.

Arr is a array of 10 character pointers

• B.

Arr is a array of function pointer.

• C.

Arr is a array of characters.

• D.

Arr is a pointer to array of characters.

A. Arr is a array of 10 character pointers
Explanation
The declaration "char *arr[10]" signifies that arr is an array of 10 character pointers. This means that arr is a collection of memory addresses, where each address points to a character. The size of the array is 10, which means it can hold 10 character pointers.

Rate this question:

• 30.

What do the following declaration signify?void *cmp();

• A.

Cmp is a pointer to an void type.

• B.

Cmp is a void type pointer variable

• C.

Cmp is a function that return a void pointer

• D.

Cmp function returns nothing

C. Cmp is a function that return a void pointer
Explanation
The declaration "void *cmp();" signifies that cmp is a function that returns a void pointer. The void pointer is a generic pointer type that can be used to point to any data type. Therefore, cmp is a function that returns a pointer to an unspecified type.

Rate this question:

• 31.

Identify which of the following are declarations1 :extern int x;2 :float square ( float x ) { ... }3 :double pow(double, double);

• A.

1

• B.

2

• C.

1 and 3

• D.

3

C. 1 and 3
Explanation
In C programming, a declaration is a statement that announces the existence of a variable or function and specifies its type. In the given options, both 1 and 3 are declarations.

1 is a declaration for an external integer variable named "x". The "extern" keyword is used to declare a variable that is defined in another file.

3 is a declaration for a function named "pow" which takes two double arguments and returns a double value. This declaration specifies the function's name, return type, and parameter types.

Rate this question:

• 32.

Suppose a program is divided into three files f1, f2 and f3, and a variable is defined in the file f1 but used in files f2 and f3. In such a case would we need the extern declaration for the variables in the files f2 and f3?

• A.

Yes

• B.

No

A. Yes
Explanation
In this scenario, we would need the extern declaration for the variable in files f2 and f3. The extern keyword is used to declare a variable that is defined in another file. By using the extern declaration, we are informing the compiler that the variable is defined in another file and can be accessed in the current file. Without the extern declaration, the compiler would not be able to find the variable and would throw an error. Therefore, in order to use the variable defined in f1 in files f2 and f3, we need to include the extern declaration.

Rate this question:

• 33.

Can we pass a variable argument list to a function at run-time?

• A.

Yes

• B.

No

B. No
Explanation
Variable argument lists, also known as varargs, allow a function to accept a variable number of arguments. However, the number and types of arguments must be known at compile-time, not at run-time. Therefore, it is not possible to pass a variable argument list to a function at run-time.

Rate this question:

• 34.

Is it necessary that in a function which accepts variable argument list there should be at least be one fixed argument?

• A.

Yes

• B.

No

A. Yes
Explanation
Yes, it is necessary to have at least one fixed argument in a function that accepts a variable argument list. This is because the fixed argument provides a reference point for the variable arguments and helps in determining the number and type of the variable arguments. Without a fixed argument, it would be difficult to handle and process the variable arguments effectively.

Rate this question:

• 35.

What are the types of linkages?

• A.

Internal and External

• B.

External, Internal and None

• C.

External and None

• D.

Internal

B. External, Internal and None
Explanation
The correct answer is External, Internal and None. This answer suggests that there are three types of linkages: external, internal, and none. External linkages refer to connections between a program and external libraries or modules. Internal linkages refer to connections within a program, such as between different functions or variables. None indicates that there may be situations where no linkages are present.

Rate this question:

• 36.

When we mention the prototype of a function?

• A.

Defining

• B.

Declaring

• C.

Prototyping

• D.

Calling

B. Declaring
Explanation
When we mention the prototype of a function, we are declaring the function. Declaring a function means providing its name, return type, and parameter types without providing the function's body. This allows the compiler to recognize the function and understand its signature, enabling the use of the function before it is defined. By declaring the prototype, we inform the compiler about the existence of the function and how it should be used, enabling proper compilation and preventing potential errors.

Rate this question:

• 37.

What is the similarity between a structure, union and enumeration?

• A.

All of them let you define new values

• B.

All of them let you define new data types

• C.

All of them let you define new pointers

• D.

All of them let you define new structures

B. All of them let you define new data types
Explanation
A structure, union, and enumeration all allow you to define new data types. A structure allows you to group different variables together under one name, creating a new composite data type. A union allows you to define a data type that can hold different types of data in the same memory space. An enumeration allows you to define a set of named values, creating a new data type with a limited number of possible values. Therefore, all three constructs enable the creation of new data types.

Rate this question:

• 38.

How will you free the allocated memory?

• A.

Remove(var-name);

• B.

Free(var-name);

• C.

Delete(var-name);

• D.

Dalloc(var-name);

B. Free(var-name);
Explanation
To free the allocated memory, the correct option is "free(var-name)". The "free()" function is used in C programming language to deallocate the memory previously allocated by the "malloc()", "calloc()", or "realloc()" functions. It releases the memory back to the system, making it available for other programs or processes to use. Therefore, "free(var-name)" is the appropriate way to release the allocated memory.

Rate this question:

• 39.

For the following statements will arr[3] and ptr[3] fetch the same character?char arr[] = "IndiaBIX";char *ptr = "IndiaBIX";

• A.

Yes

• B.

No

A. Yes
Explanation
Yes, both arr[3] and ptr[3] will fetch the same character. In the given code, arr[] is an array of characters and ptr is a pointer to a character. Both arr and ptr point to the same string "IndiaBIX". Therefore, arr[3] and ptr[3] will both fetch the character 'i' at index 3 of the string.

Rate this question:

• 40.

• A.

Yes

• B.

No