1.
Which of the following is the correct order of evaluation for the below expression?
z = x + y * z / 4 % 2 - 1
Correct Answer
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).
2.
Which of the following correctly shows the hierarchy of arithmetic operations in C?
Correct Answer
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.
3.
In which order do the following gets evaluated
1.
Relational
2.
Arithmetic
3.
Logical
4.
Assignment
Correct Answer
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.
4.
Which of the following is the correct usage of conditional operators used in C?
Correct Answer
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.
5.
What will the function rewind() do?
Correct Answer
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.
6.
Input/output function prototypes and macros are defined in which header file?
Correct Answer
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.
7.
Which standard library function will you use to find the last occurrence of a character in a string in C?
Correct Answer
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.
8.
What is stderr?
Correct Answer
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.
9.
What is the purpose of fflush() function?
Correct Answer
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.
10.
What will the function randomize() do in Turbo C under DOS?
Correct Answer
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.
11.
In which numbering system can the binary number 1011011111000101 be easily converted to?
Correct Answer
B. Hexadecimal system
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.
12.
Which bitwise operator is suitable for turning on a particular bit in a number?
Correct Answer
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.
13.
Which header file should be included to use functions like malloc() and calloc()?
Correct Answer
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.
14.
What function should be used to free the memory allocated by calloc() ?
Correct Answer
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.
15.
What are the different types of real data types in C?
Correct Answer
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.
16.
What will you do to treat the constant 3.14 as a long double?
Correct Answer
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.
17.
We want to round off x, a float, to an int value, The correct way to do is
Correct Answer
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).
18.
The binary equivalent of 5.375 is
Correct Answer
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.
19.
Which of the following function sets first n characters of a string to a given character?
Correct Answer
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.
20.
If the two strings are identical, then strcmp() function returns
Correct Answer
C. 0
Explanation
The strcmp() function is used to compare two strings. If the two strings are identical, strcmp() function returns 0.
21.
Which of the following function is used to find the first occurrence of a given string in another string?
Correct Answer
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.
22.
Which of the following function is more appropriate for reading in a multi-word string?
Correct Answer
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.
23.
How will you print \n on the screen?
Correct Answer
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.
24.
Is standard library a part of C language?
Correct Answer
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.
25.
The library function used to find the last occurrence of a character in a string is
Correct Answer
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.
26.
The itoa function can convert an integer in decimal, octal or hexadecimal form to a string.
Correct Answer
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.
27.
Scanf() or atoi() function can be used to convert a string like "436" in to integer.
Correct Answer
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".
28.
What do the following declaration signify?int *ptr[30];
Correct Answer
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.
29.
What do the following declaration signify?char *arr[10];
Correct Answer
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.
30.
What do the following declaration signify?void *cmp();
Correct Answer
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.
31.
Identify which of the following are declarations1 :extern int x;2 :float square ( float x ) { ... }3 :double pow(double, double);
Correct Answer
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.
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?
Correct Answer
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.
33.
Can we pass a variable argument list to a function at run-time?
Correct Answer
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.
34.
Is it necessary that in a function which accepts variable argument list there should be at least be one fixed argument?
Correct Answer
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.
35.
What are the types of linkages?
Correct Answer
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.
36.
When we mention the prototype of a function?
Correct Answer
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.
37.
What is the similarity between a structure, union and enumeration?
Correct Answer
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.
38.
How will you free the allocated memory?
Correct Answer
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.
39.
For the following statements will arr[3] and ptr[3] fetch the same character?char arr[] = "IndiaBIX";char *ptr = "IndiaBIX";
Correct Answer
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.
40.
Is there any difference between the two statements?
char *ch = "IndiaBIX";
char ch[] = "IndiaBIX";
Correct Answer
A. Yes
Explanation
Yes, there is a difference between the two statements. In the first statement, char *ch is a pointer variable that is pointing to the string "IndiaBIX" which is stored in the read-only memory. The value of the pointer variable cannot be changed, but it can be made to point to a different memory location. In the second statement, char ch[] is an array variable that is storing the string "IndiaBIX" in a mutable memory location. The array can be modified and its elements can be accessed using indexing.