Home Subjects C Programming Control Flow

C Programming
Control Flow

C language from basics to advanced placement prep

52 Q 10 Topics Take Mock Test
Advertisement
Difficulty: All Easy Medium Hard 41–50 of 52
Topics in C Programming
Q.41 Medium Control Flow
What will be the behavior of a for loop with an empty body and no statements inside braces?
A Compilation error
B Infinite loop
C Loop executes normally with no operations
D Loop is skipped entirely
Correct Answer:  C. Loop executes normally with no operations
EXPLANATION

A for loop with an empty body is valid syntax in C. The loop executes for the specified iterations but performs no operations in each iteration.

Test
Q.42 Medium Control Flow
Consider a switch statement with multiple cases. If a case matches and break is omitted, what happens?
A Program terminates
B Execution falls through to the next case
C Current case executes twice
D Compilation error occurs
Correct Answer:  B. Execution falls through to the next case
EXPLANATION

Without a break statement, execution continues to the next case (fall-through behavior). This is a common source of bugs if not intentional.

Test
Q.43 Medium Control Flow
Which of the following is NOT a valid use of the goto statement in C?
A Jumping forward to a label
B Jumping backward to a label
C Jumping across function boundaries
D Jumping to an error handling block
Correct Answer:  C. Jumping across function boundaries
EXPLANATION

goto cannot jump across function boundaries. It can only jump within the same function to a labeled statement either forward or backward.

Test
Q.44 Medium Control Flow
What does this code segment output?
for (int i = 0; i < 5; i++) {
if (i % 2 == 0) continue;
printf("%d ", i);
}
A 1 3
B 0 2 4
C 1 3 5
D 0 1 2 3 4
Correct Answer:  A. 1 3
EXPLANATION

continue skips even numbers. Loop prints only odd values: 1 and 3.

Test
Q.45 Medium Control Flow
Determine the output:
int i = 0;
while (i < 3) {
printf("%d ", i++);
}
A 0 1 2
B 1 2 3
C 0 1 2 3
D Infinite loop
Correct Answer:  A. 0 1 2
EXPLANATION

i starts at 0. Loop prints i then increments: prints 0, then 1, then 2. When i becomes 3, condition fails.

Test
Q.46 Medium Control Flow
What is the output?
int n = 1;
do {
printf("%d ", n);
n++;
} while (n > 5);
A 1
B 1 2 3 4 5
C No output
D Infinite loop
Correct Answer:  A. 1
EXPLANATION

The do-while executes once (prints 1), then n becomes 2. Since 2 > 5 is false, the loop exits.

Test
Q.47 Medium Control Flow
What is printed by this code?
int x = 5;
while (x-- > 0)
printf("%d ", x);
A 5 4 3 2 1 0
B 4 3 2 1 0
C 5 4 3 2 1
D 4 3 2 1
Correct Answer:  B. 4 3 2 1 0
EXPLANATION

x-- returns 5 first, then decrements to 4. Loop runs while x > 0, printing 4, 3, 2, 1, 0.

Test
Q.48 Medium Control Flow
How many times will this loop execute?
for (int i = 0; i < 5; ++i) {
if (i == 2) continue;
if (i == 4) break;
}
A 2 times
B 3 times
C 4 times
D 5 times
Correct Answer:  C. 4 times
EXPLANATION

Loop runs for i=0,1,2,3. When i=4, break is executed. The body executes 4 times (iterations for i=0,1,2,3).

Test
Q.49 Medium Control Flow
What is the output of this switch statement?
int x = 2;
switch(x) {
case 1: printf("One"); break;
case 2: printf("Two");
case 3: printf("Three"); break;
default: printf("Other");
}
A Two
B TwoThree
C Three
D TwoThreeOther
Correct Answer:  B. TwoThree
EXPLANATION

Case 2 matches. Since there's no break after case 2, fall-through occurs to case 3, printing 'TwoThree'.

Test
Q.50 Medium Control Flow
What does the following nested if-else produce?
int a = 10, b = 20;
if (a > b)
if (b > 0)
printf("X");
else
printf("Y");
A X
B Y
C XY
D No output
Correct Answer:  B. Y
EXPLANATION

The else clause pairs with the inner if. Since a > b is false, the else block executes printing 'Y'.

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