Control Structures # MCQs Practice set

Q.1 Which of the following is a looping control structure in programming?

if
switch
for
break
Explanation - The 'for' loop is used to repeat a block of code a known number of times, making it a looping control structure.
Correct answer is: for

Q.2 What is the output of the following code snippet? int x = 5; if (x > 3) { printf("Hello"); } else { printf("World"); }

Hello
World
5
Error
Explanation - Since x is 5, which is greater than 3, the 'if' block executes, printing 'Hello'.
Correct answer is: Hello

Q.3 Which statement immediately terminates the nearest enclosing loop?

continue
break
exit
return
Explanation - The 'break' statement terminates the nearest loop or switch statement in which it appears.
Correct answer is: break

Q.4 What does the 'continue' statement do in a loop?

Exits the loop
Skips the current iteration and moves to the next iteration
Pauses the loop
Restarts the program
Explanation - 'continue' skips the remaining statements in the current loop iteration and proceeds with the next iteration.
Correct answer is: Skips the current iteration and moves to the next iteration

Q.5 Which control structure is used when multiple conditions are checked sequentially?

if-else
switch-case
for loop
while loop
Explanation - 'if-else' statements evaluate conditions in sequence and execute the corresponding block when a condition is true.
Correct answer is: if-else

Q.6 What is the result of the following code? int i = 0; while (i < 3) { printf("%d", i); i++; }

012
123
0 1 2
Error
Explanation - The while loop executes while i < 3, printing 0, 1, 2 consecutively.
Correct answer is: 012

Q.7 Which of the following is NOT a conditional control structure?

if
switch
for
if-else
Explanation - The 'for' loop is a looping control structure, not a conditional one.
Correct answer is: for

Q.8 Which statement is true about a 'do-while' loop?

It executes the loop body zero or more times
It executes the loop body at least once
It only executes if the condition is true initially
It is the same as a 'while' loop
Explanation - A 'do-while' loop evaluates the condition after executing the loop body, guaranteeing at least one execution.
Correct answer is: It executes the loop body at least once

Q.9 What is the purpose of a 'switch' statement?

To perform looping
To handle multiple discrete conditions based on a single expression
To terminate a program
To call functions
Explanation - A 'switch' statement allows branching based on the value of an expression, selecting a matching case block.
Correct answer is: To handle multiple discrete conditions based on a single expression

Q.10 What is the output of the following code? for(int i=0;i<3;i++) { if(i==1) continue; printf("%d", i); }

012
02
01
0
Explanation - When i=1, 'continue' skips printing, so only 0 and 2 are printed.
Correct answer is: 02

Q.11 Which loop is best suited when the number of iterations is known beforehand?

for
while
do-while
if
Explanation - The 'for' loop is ideal when the number of iterations is predetermined.
Correct answer is: for

Q.12 Which of the following is true about nested loops?

Inner loop runs once for each outer loop iteration
Outer loop runs once for each inner loop iteration
They cannot be used in C programming
They always create infinite loops
Explanation - In nested loops, the inner loop executes completely for every iteration of the outer loop.
Correct answer is: Inner loop runs once for each outer loop iteration

Q.13 What is the output of this code? int x=2; switch(x) { case 1: printf("A"); break; case 2: printf("B"); break; default: printf("C"); }

A
B
C
Error
Explanation - Since x=2, case 2 matches and 'B' is printed.
Correct answer is: B

Q.14 Which statement is used to skip the remaining statements in a loop iteration and proceed to the next iteration?

break
continue
exit
return
Explanation - 'continue' skips the current iteration and moves to the next loop iteration.
Correct answer is: continue

Q.15 Which of the following loops is guaranteed to execute at least once?

for
while
do-while
None
Explanation - In a 'do-while' loop, the loop body executes first, then the condition is checked.
Correct answer is: do-while

Q.16 What is the output? int i=0; do { printf("%d", i); i++; } while(i<3);

012
123
0 1 2
Error
Explanation - The do-while loop prints 0, 1, 2 as i increments from 0 to 2.
Correct answer is: 012

Q.17 Which of the following is correct about 'if-else if-else' ladder?

All conditions are checked even after a match
Only the first true condition block executes
It can only have one condition
It can replace loops
Explanation - In an 'if-else if-else' ladder, only the block corresponding to the first true condition executes.
Correct answer is: Only the first true condition block executes

Q.18 Which control structure would you use to repeatedly execute a block until a certain condition becomes false?

if
switch
loop
function
Explanation - Loops (for, while, do-while) execute repeatedly until a given condition is false.
Correct answer is: loop

Q.19 What is the output? for(int i=1;i<=3;i++) { for(int j=1;j<=2;j++) { printf("%d", i*j); } }

123456
12 23 36
122436
Error
Explanation - The outer loop runs 3 times and inner loop 2 times; products printed sequentially: 1*1=1,1*2=2,2*1=2,2*2=4,3*1=3,3*2=6.
Correct answer is: 122436

Q.20 Which statement can be used to exit a switch-case structure?

break
continue
return
exit
Explanation - 'break' exits the switch-case; without it, execution falls through to subsequent cases.
Correct answer is: break

Q.21 Which of the following loops is entry-controlled?

for
while
do-while
Both for and while
Explanation - In 'for' and 'while' loops, the condition is checked before entering the loop, making them entry-controlled.
Correct answer is: Both for and while

Q.22 What is the default case in a switch statement used for?

To terminate the program
To execute when no case matches
To execute only if case 0 exists
To execute before all cases
Explanation - The 'default' block runs when none of the specified cases match the switch expression.
Correct answer is: To execute when no case matches

Q.23 Which control structure can lead to infinite execution if not correctly managed?

if-else
switch
loops
function calls
Explanation - Improperly controlled loops (like while(true)) can result in infinite execution.
Correct answer is: loops

Q.24 In C programming, which symbol is used to terminate a case in switch statement?

;
:
break;
end;
Explanation - 'break;' ends the execution of a case in switch and prevents fall-through.
Correct answer is: break;