Home Subjects C Programming Control Flow

C Programming
Control Flow

C language from basics to advanced placement prep

12 Q 10 Topics Take Mock Test
Advertisement
Difficulty: All Easy Medium Hard 1–10 of 12
Topics in C Programming
Q.1 Hard Control Flow
Consider the code:
int sum = 0;
for(int i = 1; i
A 25
B 55
C 30
D 45
Correct Answer:  A. 25
EXPLANATION

The loop adds only odd numbers (1,3,5,7,9) due to the continue statement when i is even. Sum = 1+3+5+7+9 = 25.

Test
Q.2 Hard Control Flow
What will be printed?
int i = 0, j = 0;
for(i = 0; i < 3; i++) {
for(j = 0; j < 3; j++) {
if(i + j == 2) break;
printf("%d%d ", i, j);
}
}
A 00 01 10
B 00 01 10 11 20 21
C 00 01 11 20 21
D 00 10 20
Correct Answer:  A. 00 01 10
EXPLANATION

Inner break only exits the inner loop. i=0,j=0: prints 00; i=0,j=1: prints 01, breaks when j=2; i=1,j=0: prints 10, breaks when j=1; i=2,j=0: breaks immediately.

Test
Q.3 Hard Control Flow
What will this code print?
int x = 0;
while(x < 3) {
printf("%d ", x++);
if(x == 2) continue;
printf("X ");
}
A 0 X 1 2 X
B 0 X 1 X 2 X
C 0 1 2
D 0 X 1 2
Correct Answer:  D. 0 X 1 2
EXPLANATION

Iteration 1: prints 0, x becomes 1, continue not triggered, prints X. Iteration 2: prints 1, x becomes 2, continue triggered, skips X. Iteration 3: prints 2, x becomes 3, condition fails.

Test
Q.4 Hard Control Flow
What is the output?
for(int i = 0; i < 3; i++)
for(int j = 0; j < 3; j++)
if(i == j) continue;
printf("Done");
A Done
B Done printed 9 times
C No output
D Compilation error
Correct Answer:  A. Done
EXPLANATION

continue only skips the current iteration of innermost loop, not the outer. After both loops complete, 'Done' is printed once.

Test
Q.5 Hard Control Flow
Which statement best describes the 'dangling else' problem in C?
A else cannot be used with nested if statements
B Else binds to the nearest preceding if without an else
C Multiple else statements cause compilation error
D Else keyword must be on same line as if
Correct Answer:  B. Else binds to the nearest preceding if without an else
EXPLANATION

Dangling else refers to ambiguity when else could bind to multiple if statements. C resolves this by binding else to the nearest if.

Test
Q.6 Hard Control Flow
What will this code do?
int i = 0;
while(i < 5) {
printf("%d ", i++);
if(i == 3) break;
}
A Prints: 0 1 2
B Prints: 0 1 2 3
C Prints: 1 2 3
D Infinite loop
Correct Answer:  A. Prints: 0 1 2
EXPLANATION

Post-increment: prints 0 (i becomes 1), prints 1 (i becomes 2), prints 2 (i becomes 3). When i==3, break executes. Output: 0 1 2

Test
Q.7 Hard Control Flow
What is the output of:
for(int i = 0; i < 2; i++)
for(int j = 0; j < 2; j++)
if(i == j) continue;
printf("Done");
A Done
B Nothing printed
C DoneDoneDone (three times)
D Compilation error
Correct Answer:  A. Done
EXPLANATION

continue skips current iteration but doesn't affect outer loop. After nested loops complete, 'Done' prints once.

Test
Q.8 Hard Control Flow
What is the output of this complex nested loop?
for(int i = 1; i
A 11 12 21 22
B 12 21
C 11 22
D 12 21 22
Correct Answer:  B. 12 21
EXPLANATION

continue skips when i==j. i=1: prints 12 (skips 11); i=2: prints 21 (skips 22). Output: 12 21

Test
Q.9 Hard Control Flow
What is the effect of using multiple break statements in nested loops?
A All nested loops terminate at once
B Only the innermost loop terminates
C Each break terminates its corresponding loop level
D Compilation error occurs
Correct Answer:  C. Each break terminates its corresponding loop level
EXPLANATION

Each break statement exits only its immediately enclosing loop. To exit multiple nested loops, you need one break for each level you want to exit.

Test
Q.10 Hard Control Flow
What happens when continue is used in a for loop with a post-increment expression?
A The increment is skipped
B The increment still executes
C Loop terminates
D Infinite loop occurs
Correct Answer:  B. The increment still executes
EXPLANATION

When continue is executed in a for loop, the post-increment (i++) still executes before the condition is checked again. Only the body statements after continue are skipped.

Test
IGET
IGET AI
Online · Exam prep assistant
Hi! 👋 I'm your iget AI assistant.

Ask me anything about exam prep, MCQ solutions, study tips, or strategies! 🎯
UPSC strategy SSC CGL syllabus Improve aptitude NEET Biology tips