WorksheetsIf-Else Statements Practice Set 1
Total questions: 20
Worksheet time: 10mins
What will be the output of the following code? int x = 5; if (x > 4) printf("A"); if (x > 6) printf("B"); else printf("C");
A
ABC
AC
C
Which of the following is TRUE about if statement in C?
Condition must be float
Condition must be Boolean
Condition must be integer
Curly braces are compulsory
What will be the output? int a = 0; if (a = 5) printf("Yes"); else printf("No");
Error
Undefined
No
Yes
default case in switch is:
Mandatory
Optional
Must be first
Must be last
How many times will the loop execute? int i; for(i = 0; i < 10; i += 3);
0
3
Infinite
Error
What is the output? int i = 1; while(i <= 5) { printf("%d ", i); i += 2; } A. 1 2 3 4 5 B. 1 3 5 C. 2 4 D. Infinite loop
1 3 5
Infinite loop
1 2 3 4 5
2 4
Difference between while and do-while loop is:
None
do-while executes at least once
Both same
while executes at least once
What will be the output? int i = 0; for(; i < 3; ) printf("%d ", i++);
0 1 2
Error
Infinite
1 2 3
switch statement internally works like:
recursion
loop
if-else ladder
macro
What is the output? int x = 5; if(x = 0) printf("A"); else printf("B");
Runtime error
A
Compilation error
B
Which of the following is TRUE about if statements?
Nested if is allowed
if cannot be used without else
else is mandatory
Multiple else blocks are allowed
What is the output? int a = 10; if(a > 5) if(a < 15) printf("X"); else printf("Y");
X
Y
Compilation error
No output
default case in switch is:
Mandatory
Must be last
Must be first
Optional
How many times will the loop execute? int i = 1; while(i <= 10) { i = i * 2; }
Infinite
4
3
2
What is the output? int i = 0; do { printf("%d ", i); i++; } while(i < 0);
Compilation error
Infinite
No output
0
break statement is used to:
Exit loop or switch
Skip current iteration
Terminate program
Pause execution
What is the output? int i = 5; if(i = 10) printf("YES"); else printf("NO");
YES
NO
Error
Depends on compiler
Which loop is guaranteed to execute at least once?
while
do-while
infinite loop
for
Which of the following causes an infinite loop?
for(;;)
while(1)
do { } while(1);
All of the above
Which statement is TRUE?
switch supports float values
break is mandatory in switch
case labels must be constants
switch can use relational expressions
