Module 4: Control Statements & Loops - Final Quiz MCQs
Solve topic-wise placement questions and improve your skills.
switch statement?int
char
double
enum
What is the output of the following C code demonstrating switch-case fallthrough?
#include <stdio.h>
int main() {
int x = 2;
switch (x) {
case 1: printf("One ");
case 2: printf("Two ");
case 3: printf("Three ");
default: printf("Default");
}
return 0;
}Two
Two Three Default
Two Three
Default
What is the output of the following C code containing a trailing semicolon after if?
#include <stdio.h>
int main() {
int a = 10;
if (a > 20);
{
printf("Condition Passed ");
}
printf("End");
return 0;
}End
Condition Passed End
Condition Passed
Compile error
What is the output of the following do-while loop?
#include <stdio.h>
int main() {
int i = 5;
do {
printf("%d ", i);
i++;
} while (i < 5);
return 0;
}Nothing is printed
5
5 6
Infinite loop
What is the output of the following loop utilizing the comma operator in initialization and step?
#include <stdio.h>
int main() {
int i, j;
for (i = 0, j = 4; i < j; i++, j--) {
printf("%d%d ", i, j);
}
return 0;
}04 13
04 13 22
04 14 24
04
What happens when the following code with a continue statement inside a while loop is executed?
#include <stdio.h>
int main() {
int i = 0;
while (i < 3) {
if (i == 1) {
continue;
}
printf("%d ", i);
i++;
}
return 0;
}0 2
0 1 2
0 followed by an infinite loop
0 1
What is the output of the following code illustrating the classic "Dangling Else" problem?
#include <stdio.h>
int main() {
int x = 5, y = 10;
if (x > 10)
if (y > 5)
printf("Alpha");
else
printf("Beta");
return 0;
}Beta
Alpha
Nothing is printed
Compile error
What is the output of this code with variable mutation across switch cases?
#include <stdio.h>
int main() {
int a = 1;
switch (a) {
case 1: a += 3;
case 2: a += 2; break;
case 3: a += 1;
}
printf("%d", a);
return 0;
}4
6
7
3
What is the behavior of the following loop with a trailing semicolon?
#include <stdio.h>
int main() {
int i = 1;
while (i <= 5);
{
printf("%d ", i);
i++;
}
return 0;
}1 2 3 4 5
1
Infinite loop with no console output
Compile error
Why is using a floating-point counter in the loop below considered dangerous in systems programming?
for (float f = 0.0f; f != 1.0f; f += 0.2f) {
// ...
}f to skip 1.0f, resulting in an infinite loop
continue
break
goto
return