1.
Which of the following statements should be used to obtain a remainder after dividing 3.14 by 2.1 ?
Correct Answer
C. Rem = fmod(3.14, 2.1);
Explanation
The function fmod(3.14, 2.1) should be used to obtain the remainder after dividing 3.14 by 2.1.
2.
Point out the error in the following program #include<stdio.h>
int main()
{
display();
return 0;
}
void display()
{
printf("Welcome To Tait");
}
Correct Answer
C. Display() is called before it is defined
Explanation
The error in the program is that the function display() is called before it is defined. In C programming, functions need to be declared or defined before they are used. In this program, the main() function calls the display() function before it is actually defined. To fix this error, the display() function should be defined or declared before the main() function.
3.
Which statement will you add in the following program to work it correctly? #include<stdio.h>
int main()
{
printf("%f\n", log(36.0));
return 0;
}
Correct Answer
B. #include(math.h)
Explanation
The correct answer is #include(math.h). This is because the log() function is used in the program, which is a mathematical function. Including the math.h header file allows the program to access the necessary function and perform the logarithmic calculation correctly.
4.
In which header file is the NULL macro defined?
Correct Answer
C. Stdio.h and stddef.h
Explanation
The NULL macro is defined in both stdio.h and stddef.h header files. These header files are part of the C standard library and provide various functions and macros. stdio.h is used for input and output operations, while stddef.h is used for defining several types and macros, including NULL. Therefore, to use the NULL macro in a C program, either stdio.h or stddef.h (or both) can be included.
5.
Point out the error in the program #include<stdio.h>
int main()
{
int a[] = {10, 20, 30, 40, 50};
int j;
for(j=0; j<5; j++)
{
printf("%d\n", a);
a++;
}
return 0;
}
Correct Answer
C. Error: LValue required
Explanation
The error in the program is "Error: LValue required". This error occurs because the variable "a" is being incremented in the line "a++", which is not allowed because "a" is an array and arrays are not modifiable lvalues. Modifying an array name is not allowed in C.
6.
Which bitwise operator is suitable for checking whether a particular bit is on or off?
Correct Answer
B. & operator
Explanation
The & operator is suitable for checking whether a particular bit is on or off. This operator performs a bitwise AND operation between two operands. When used with a specific bit and the value 1, it will return 1 if the bit is on (1) and 0 if the bit is off (0).
7.
Assunming, integer is 2 byte, What will be the output of the program? #include<stdio.h>
int main()
{
printf("%x\n", -1>>1);
return 0;
}
Correct Answer
A. Ffff
Explanation
The program uses the right shift operator (>>) to shift the bits of -1 by 1 position to the right. Since -1 is represented in two's complement form, all bits are set to 1. Shifting the bits to the right by 1 position will result in the value being divided by 2, and the sign bit (MSB) will be retained. Therefore, the output will be "ffff" in hexadecimal, which represents the decimal value -1.
8.
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 block previously allocated by malloc(), calloc(), or realloc(). By using free(), the memory allocated by calloc() is released and can be reused for other purposes.
9.
What will be the output of the program? #include
#include
int main()
{
char *s;
char *fun();
s = fun();
printf("%s\n", s);
return 0;
}
char *fun()
{
char buffer[30];
strcpy(buffer, "RAM");
return (buffer);
}
Correct Answer
B. Garbage value
Explanation
The program is trying to print the value of the string `s` which is assigned the return value of the `fun()` function. However, the `fun()` function is returning the address of a local variable `buffer` which is a character array. Once the `fun()` function finishes executing, the memory allocated for the `buffer` variable is deallocated, and accessing that memory location through `s` will result in undefined behavior. This can lead to garbage values being printed.
10.
Which standard library function will you use to find the last occurance 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. This function takes two arguments - the string in which we want to search for the character, and the character we want to find. It returns a pointer to the last occurrence of the character in the string, or NULL if the character is not found.
11.
How many times the program will print "vardhaman" ? #include<stdio.h>
int main()
{
printf("vardhaman");
main();
return 0;
}
Correct Answer
D. Till stack overflows
Explanation
The program will print "vardhaman" until the stack overflows. This is because the main function calls itself recursively without any termination condition, causing an infinite loop. As the function keeps calling itself without returning, it consumes more and more stack space until it exceeds the maximum stack size, resulting in a stack overflow.
12.
Which of the following statements are correct about the program? #include<stdio.h>
int main()
{
printf("%d\n", main());
return 0;
}
Correct Answer
B. Runs infinitely without printing anything
Explanation
The program runs infinitely because the main function is recursively calling itself within the printf statement. This creates an infinite loop where the program keeps calling main without any condition to stop. As a result, the program does not print anything and continues to run indefinitely.
13.
What does the following declaration mean?int (*ptr)[10];
Correct Answer
B. Ptr is a pointer to an array of 10 integers
Explanation
The declaration "int (*ptr)[10];" means that ptr is a pointer to an array of 10 integers. This means that ptr can be used to access and manipulate the elements of an array that contains 10 integers.
14.
What will be the output of the program ? #include<stdio.h>
void fun(int **p);
int main()
{
int a[3][4] = {1, 2, 3, 4, 4, 3, 2, 8, 7, 8, 9, 0};
int *ptr;
ptr = &a[0][0];
fun(&ptr);
return 0;
}
void fun(int **p)
{
printf("%d\n", **p);
}
Correct Answer
A. 1
Explanation
The program defines a 2D array `a` and a pointer `ptr` which points to the first element of the array. The function `fun` is called with the address of `ptr` as an argument. Inside the function, the value at the address pointed by `p` is printed, which is the value at the first element of the array `a`. Therefore, the output of the program will be 1.
15.
What will be the output of the program ? #include<stdio.h>
int main()
{
float arr[] = {12.4, 2.3, 4.5, 6.7,11.2};
printf("%d\n", sizeof(arr)/sizeof(arr[0]));
return 0;
}
Correct Answer
C. 5
Explanation
The program declares an array of float values and initializes it with 5 elements. The sizeof operator is used to calculate the total number of bytes occupied by the array, and this value is divided by the number of bytes occupied by a single element of the array. Since each element of the array is of type float, which typically occupies 4 bytes, the result of the division is 5. Therefore, the output of the program will be 5.
16.
What does fp point to in the program ? #include<stdio.h>
int main()
{
FILE *fp;
fp=fopen("trial", "r");
return 0;
}
Correct Answer
B. A structure which contains a char pointer which points to the first character of a file.
Explanation
The variable "fp" is a pointer to a structure of type FILE. This structure contains a char pointer which points to the first character of a file. In this program, the fopen function is used to open the file named "trial" in read mode, and the file pointer "fp" is assigned the address of this opened file. Therefore, "fp" points to the first character of the file.
17.
Which of the following are unary operators in C?1. !2. sizeof3. ~4. &&
Correct Answer
D. 1,2,3
Explanation
The correct answer is 1,2,3. In C, the unary operators are operators that operate on a single operand. The exclamation mark (!) is the logical NOT operator, the sizeof operator is used to determine the size of a variable or data type, and the tilde (~) is the bitwise NOT operator. Therefore, options 1, 2, and 3 are the unary operators in C. Option 4, &&, is the logical AND operator, which is a binary operator as it operates on two operands.
18.
What will be the output of the program? #include<stdio.h>
int main()
{
int i=-3, j=2, k=0, m;
m = ++i || ++j && ++k;
printf("%d, %d, %d, %d\n", i, j, k, m);
return 0;
}
Correct Answer
D. -2, 2, 0, 1
Explanation
In this program, the variables i, j, k, and m are initialized with the values -3, 2, 0, and uninitialized respectively.
The expression "++i || ++j && ++k" is evaluated and assigned to m.
Since "++i" is true (-2), the rest of the expression is not evaluated.
Therefore, i becomes -2, j remains 2, k remains 0, and m becomes 1.
The output of the program is -2, 2, 0, 1.
19.
What will be the output of the program ? #include<stdio.h>
#include<string.h>
int main()
{
char str1[20] = "Hello", str2[20] = " World";
printf("%s\n", strcpy(str2, strcat(str1, str2)));
return 0;
}
Correct Answer
C. Hello World
Explanation
The program first concatenates the strings str1 and str2 using the strcat() function, resulting in "Hello World". Then, it copies the concatenated string to str2 using the strcpy() function. Finally, it prints the value of str2, which is "Hello World".
20.
What do the 'c' and 'v' in argv stands for?
Correct Answer
C. 'c' means argument count 'v' means argument vector
Explanation
The 'c' in argv stands for argument count, which refers to the number of command-line arguments passed to the program. The 'v' stands for argument vector, which is an array of strings that holds the actual command-line arguments.
21.
What will the SWAP macro in the following program be expanded to on preprocessing? will the code compile? #include<stdio.h>
#define SWAP(a, b, c)(c t; t=a, a=b, b=t)
int main()
{
int x=10, y=20;
SWAP(x, y, int);
printf("%d %d\n", x, y);
return 0;
}
Correct Answer
C. Not compile
Explanation
The SWAP macro in the program is not correctly defined. The macro expects three arguments, but it is only given two arguments in the main function. Therefore, the code will not compile.
22.
Which header file should be included to use functions like malloc() and calloc()?
Correct Answer
B. Stdlib.h
Explanation
The correct answer is stdlib.h. This header file should be included to use functions like malloc() and calloc(). The stdlib.h header file in C provides functions for general-purpose use, including memory allocation and deallocation functions like malloc() and calloc(). These functions are used to dynamically allocate memory during program execution. Including stdlib.h allows the program to access these functions and perform memory allocation operations.
23.
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 demonstrated in the given answer: max = a>b ? a>c?a:c:b>c?b:c. This expression uses nested ternary operators to determine the maximum value among three variables. 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.
24.
The keyword used to transfer control from a function back to the calling function is
Correct Answer
D. Return
Explanation
The keyword "return" is used to transfer control from a function back to the calling function. When a function is called, the control is passed to that function and it starts executing its code. However, at some point, the function may need to return a value or simply terminate and pass control back to the calling function. This is achieved by using the "return" keyword, which not only transfers control back to the calling function but also can return a value if specified.
25.
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 because each hexadecimal digit represents four binary digits. In this case, the binary number can be divided into groups of four digits from right to left (1011, 0111, 1100, 0101), which can then be converted to their corresponding hexadecimal digits (B, 7, C, 5). Therefore, the binary number 1011011111000101 can be easily converted to the hexadecimal system.