C Programming [MCQ] : Features of C (Multiple Choice Questions)
Question 1 |
How many times below for loop will be executed ?
#include<stdio.h> int main() { int i=0; for(;;) printf("%d",i); return 0; }
0 times | |
Infinite times | |
1 times | |
10 times |
Question 2 |
Find output of the following program ?
#include<stdio.h> int main() { char str[] = "Smaller"; int a = 100; printf(a > 10 ? "Greater" : "%s", str); return 0; }
Compile Error | |
Smaller | |
Greater | |
100 |
Question 2 Explanation:
printf(a > 10 ? "Greater" : "%s", str);is equivalent to -
if(a > 10) printf("Greater"); else printf("%s", str);
Question 3 |
Guess the output of the following program ?
#include<stdio.h> int main() { int a = 100, b = 200, c = 300; if(!a >= 500) b = 300; c = 400; printf("%d,%d,%d",a, b, c); return 0; }
100,200,400 | |
100,300,400 | |
100,200,300 | |
100,300,300 |
Question 3 Explanation:
Condition = if(!a >= 500) = if(!100 >= 500) = if(0 >= 500) = if(false)If statement will not be executed and thus value of 'c' will remain unchanged.
Question 4 |
Guess the output of the following program :
#include<stdio.h> int main() { int x = 10; float y = 10.0; if(x == y) printf("x and y are equal"); else printf("x and y are not equal"); return 0; }
x and y are not equal | |
Run Time Error | |
Compile Error | |
x and y are equal |
Question 5 |
Guess the output of the program ?
#include<stdio.h> int main() { int a=0, b=1, c=2; *((a+1 == 1) ? &b : &a) = a ? b : c; printf("%d, %d, %d\n", a, b, c); return 0; }
1,1,2 | |
0, 2, 2 | |
0,1,2 | |
2,2,2 |
Question 5 Explanation:
Step 1 : a,b and c are initialized to 0,1 and 2
Step 2 :
(a+1 == 1)is true condition hence if part will be executed. i.e expression can be written as -
*(&b) = a ? b : c; b = a ? b : c; b = 0 ? 1 : 2; b = 2
There are 5 questions to complete.