1.
Which of the following is not a valid variable name declaration?
Correct Answer
C. Int 9_a;
Explanation
The variable name "int 9_a;" is not a valid declaration because it starts with a number, which is not allowed in variable names. Variable names in most programming languages must start with a letter or an underscore.
2.
Which of the following is a valid C variable name?
Correct Answer
D. All
Explanation
All of the given options are valid C variable names. In C, a variable name can consist of letters, digits, and underscores. It must start with a letter or an underscore and cannot be a reserved word. The variable names "number", "floating", and "doubleint" all adhere to these rules and are therefore valid C variable names.
3.
Which is correct with respect to size of the datatypes?
Correct Answer
C. Char < int < double
Explanation
The correct answer is "char < int < double" because in terms of size, a char data type is smaller than an int data type, and an int data type is smaller than a double data type.
4.
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 expression is as follows: multiplication (*), division (/), modulus (%), addition (+), and subtraction (-). This means that the multiplication operation is performed first, followed by division, modulus, addition, and finally subtraction.
5.
What is the output of this C code?
int main()
{
int x = 2, y = 0;
int z = (y++) ? y == 1 && x : 0;
printf("%d\n", z);
return 0;
}
Correct Answer
B. 0
Explanation
In this code, the variable "y" is incremented using the post-increment operator. The expression "(y++)" evaluates to false because the value of "y" before the increment is 0. Therefore, the condition of the ternary operator is false and the value of "z" is assigned as 0. Finally, the value of "z" is printed, which is 0.
6.
Which of the following is not an arithmetic operation?
Correct Answer
C. A != 10;
Explanation
The given options are all arithmetic operations except for "a != 10". The other options, a *= 10, a /= 10, and a %= 10, are all examples of arithmetic operations where the value of 'a' is modified based on the operation performed. However, "a != 10" is a comparison operation, specifically a not-equal-to comparison, which checks if the value of 'a' is not equal to 10. Therefore, "a != 10" is not an arithmetic operation.
7.
What is the output of this C code?
#include <stdio.h>
void main()
{
double x = 123828749.66;
int y = x;
printf("%d\n", y);
printf("%lf\n", y);
}
Correct Answer
D. 123828749, 0.000000
Explanation
The code declares a double variable x and initializes it with the value 123828749.66. Then, it declares an integer variable y and assigns the value of x to y. When a double value is assigned to an integer variable, the decimal part is truncated. Therefore, y will have the value 123828749.
In the first printf statement, the %d format specifier is used to print the value of y as an integer, so it will output 123828749.
In the second printf statement, the %lf format specifier is used to print the value of y as a double, so it will output 0.000000.
8.
What is the output of this C code?
#include <stdio.h>
void main()
{
int x = 4, y, z;
y = --x;
z = x--;
printf("%d%d%d", x, y, z);
}
Correct Answer
B. 2 3 3
Explanation
The code begins by assigning the value 4 to the variable x. Then, the value of x is decremented by 1 and assigned to the variable y using the pre-decrement operator (--x). So, y becomes 3 and x becomes 3. Next, the value of x (which is now 3) is assigned to the variable z using the post-decrement operator (x--). So, z becomes 3 and x becomes 2. Finally, the printf statement prints the values of x, y, and z, which are 2, 3, and 3 respectively. Therefore, the output of the code is 2 3 3.
9.
Property which allows to produce different executable for different platforms in C is called?
Correct Answer
C. Conditional compilation
Explanation
Conditional compilation is the property in C that allows the production of different executables for different platforms. It allows certain sections of code to be included or excluded during the compilation process based on specific conditions. This enables developers to write platform-specific code and customize the behavior of the program based on the target platform. By using conditional compilation directives such as #ifdef and #endif, different code paths can be selected for different platforms, ensuring that the executable produced is tailored to the specific requirements of each platform.
10.
What will be the output of the following program?
#include<stdio.h>
#define square(x) x*x
void main()
{
int i;
i = 64/square(4);
printf("%d", i);
}
Correct Answer
B. 64
Explanation
The program defines a macro called square which takes a parameter x and returns the square of x. In the main function, the variable i is assigned the value of 64 divided by the result of square(4), which is 4*4. Therefore, i is assigned the value of 64/16, which is 4. The printf statement then prints the value of i, which is 4.
11.
What is the output of this C code?
#include <stdio.h>
const int a = 1, b = 2;
int main()
{
int x = 1;
switch (x)
{
case a:
printf("yes ");
case b:
printf("no\n");
break;
} }
Correct Answer
D. Compile time error
Explanation
The code will result in a compile-time error because the case labels in a switch statement must be constant expressions. In this code, the case labels are variables (a and b) which are not constant expressions. Therefore, the code will not compile successfully.
12.
Comment on the output of this C code?
#include <stdio.h>
int main()
{
int a = 1;
if (a)
printf("All is Well ");
printf("I am Well\n");
else
printf("I am not a River\n");
}
Correct Answer
D. Compile time errors during compilation
Explanation
The code will not produce any compile time errors. The if statement checks if the variable "a" is true or non-zero. Since "a" is initialized to 1, the condition will be true and the code inside the if block will be executed. Therefore, the output will be "All is Well I am Well".
13.
What will be the value of i and j after execution of following program?
#include<stdio.h>
void main()
{
int i, j;
for(i=0,j=0;i<10,j<20;i++,j++)
{
printf("i=%d %t j=%d", i, j);
}
}
Correct Answer
C. 20 20
Explanation
The program includes a for loop that iterates as long as both i is less than 10 and j is less than 20. It increments both i and j by 1 after each iteration. The loop will continue until either i becomes equal to 10 or j becomes equal to 20. Since i and j are incremented by 1 in each iteration, the loop will execute a total of 10 times. Therefore, after the execution of the program, the final values of i and j will be 10 and 20 respectively.
14.
What is the output of this C code?
#include <stdio.h>
int main()
{
int i = 0;
while (i = 0)
printf("True\n");
printf("False\n");
}
Correct Answer
C. False
Explanation
The code will output "False". This is because the condition in the while loop is "i = 0", which is an assignment statement rather than a comparison. As a result, the value of "i" will always be set to 0 and the loop will never be executed. Therefore, the program will directly move to the statement after the while loop, which is the printf statement that prints "False".
15.
What is the output of this C code?
#include <stdio.h>
int main()
{
printf("before continue ");
continue;
printf("after continue\n");
}
Correct Answer
D. Compile time error
Explanation
The output of this C code is "Compile time error". This is because the "continue" statement is used outside of a loop, which is not allowed in C. The "continue" statement is used to skip the rest of the current iteration of a loop and move on to the next iteration. Since there is no loop in this code, using "continue" results in a compile time error.
16.
Comment on the following statement:
int (*a)[7];
Correct Answer
B. A pointer “a” to an array.
Explanation
The statement "int (*a)[7]" declares a pointer "a" to an array of 7 integers. This means that "a" can store the memory address of an array, and that array must have 7 elements, each of which is an integer. The parentheses around "*a" indicate that "a" is a pointer, and the "[7]" indicates that it points to an array of size 7. Therefore, the correct answer is "A pointer 'a' to an array."
17.
What is the output of this C code?
#include <stdio.h>
void main()
{
int a[2][3] = {1, 2, 3, , 4, 5};
int i = 0, j = 0;
for (i = 0; i < 2; i++)
for (j = 0; j < 3; j++)
printf("%d", a[i][j]);
}
Correct Answer
B. Compile time error
Explanation
The given code will result in a compile time error. This is because there is a missing value in the initialization of the array "a". In the second row of the initialization, there is a comma without a value, which is not allowed. Therefore, the code will fail to compile.
18.
What is the output of this C code?
#include <stdio.h>
void main()
{
static int x = 3;
x++;
if (x <= 5)
{
printf("hi");
main();
} }
Correct Answer
D. Hi hi
Explanation
The output of this C code is "hi hi". The code defines a static variable "x" with an initial value of 3. It then increments "x" by 1. The code then checks if "x" is less than or equal to 5. Since "x" is now 4, the condition is true and the code prints "hi". After printing "hi", the code calls the main() function recursively. This process continues until "x" becomes 6, at which point the condition becomes false and the recursion stops. Therefore, "hi" is printed twice, resulting in the output "hi hi".
19.
Which files will get closed through the fclose() in the following program?
#include<stdio.h>
int main()
{
FILE *fs, *ft, *fp;
fp = fopen("A.C", "r");
fs = fopen("B.C", "r");
ft = fopen("C.C", "r");
fclose(fp, fs, ft);
return 0;
}
Correct Answer
D. Error in fclose()
Explanation
The fclose() function in C is used to close a file. However, fclose() can only close one file at a time. In the given program, the fclose() function is called with three arguments (fp, fs, ft), which is incorrect. Therefore, the correct answer is "Error in fclose()" as the fclose() function cannot close multiple files simultaneously.
20.
What will be the output of the program ?
#include<stdio.h>
int main()
{
enum days {MON=-1, TUE, WED=6, THU, FRI, SAT};
printf("%d, %d, %d, %d, %d, %d\n", MON, TUE, WED, THU, FRI, SAT);
return 0;
}
Correct Answer
D. -1, 0, 6, 7, 8, 9
Explanation
The program defines an enumeration called "days" with the values MON=-1, TUE=0, WED=6, THU=7, FRI=8, and SAT=9. In the printf statement, the values of MON, TUE, WED, THU, FRI, and SAT are printed. Therefore, the output of the program will be -1, 0, 6, 7, 8, 9.