C Programming MCQ : Conditional Operators (Multiple Choice Questions)
Question 1 |
Guess the output of the following program ?
#include<stdio.h> int main() { int num1 = 30; int num2 = 40; int ans = num1 > num2; printf("%d",ans); return(0); }
30 | |
0 | |
1 | |
40 |
Question 2 |
How many times printf will be executed ?
#include<stdio.h> int main() { int x; for(x=0; x<=15; x++) { if(x < 5) continue; else break; printf("c4learn.com"); } return 0; }
15 times | |
0 times | |
5 times | |
16 times |
Question 2 Explanation:
Continue statement will take control back to the beginning of the loop. 
Question 3 |
How many times "c4learn.com" gets printed ?
#include<stdio.h> int main() { int x; for(x=0; x<=15; x++); { printf("c4learn.com"); } return 0; }
16 times | |
0 times | |
15 times | |
1 times |
Question 3 Explanation:
Note semicolon at the end of for loop. Semicolon at the end of for loop will be equivalent to -
for(x=0; x<=15; x++) { }above program will be equivalent to -
#include<stdio.h> int main() { int x; for(x=0; x<=15; x++) { } { printf("c4learn.com"); } return 0; }
Question 4 |
Guess the output of the following program ?
#include<stdio.h> int main() { int x; for(x=0; x<=3; x++); { printf("x = %d",x); } return 0; }
x = 0 x = 1 x = 2 x = 3 x = 4 | |
x = 4 | |
x = 0 x = 1 x = 2 x = 3 | |
x = 3 |
Question 4 Explanation:
Note the semicolon at the end of for loop. Loop will be executed 5 times and final value of x will be 4.
Question 5 |
What will be the output of the program?
#include<stdio.h> int main() { int i=0; for(; i<=5; i++); printf("%d,", i); return 0; }
1, 2, 3, 4 | |
5 | |
0, 1, 2, 3, 4, 5 | |
6 |
Question 5 Explanation:
Noe the semicolon at the end of for loop. Above program is equivalent to -
#include<stdio.h> int main() { int i=0; for(; i<=5; i++) { } printf("%d,", i); return 0; }
There are 5 questions to complete.