C Programming
C language from basics to advanced placement prep
198 Questions 10 Topics Take Test
Advertisement
Showing 151–160 of 198 questions
Q.151 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.

Take Test
Q.152 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.

Take Test
Q.153 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.

Take Test
Q.154 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.

Take Test
Q.155 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

Take Test
Q.156 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.

Take Test
Q.157 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

Take Test
Q.158 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.

Take Test
Q.159 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.

Take Test
Q.160 Hard Control Flow
What is the output of this complex nested control flow?
int x = 1, y = 2;
if (x < y) {
x++; y--;
if (x == y)
printf("Equal");
else
printf("NotEqual");
}
A Equal
B NotEqual
C No output
D Compilation error
Correct Answer:  A. Equal
EXPLANATION

x=1, y=2. Since 1 < 2, x becomes 2 and y becomes 1. Now x != y, but after operations x=2, y=1. Wait: x++ makes x=2, y-- makes y=1. So x==y is false, printing 'NotEqual'. Rechecking: 1 < 2 is true, so enter if. x becomes 2, y becomes 1. 2 == 1 is false, so else executes, printing 'NotEqual'.

Take Test
IGET
iget AI
Online · Ask anything about exams
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