Home Subjects C Programming Control Flow

C Programming
Control Flow

C language from basics to advanced placement prep

100 Q 10 Topics Take Test
Advertisement
Difficulty: All Easy Medium Hard 31–40 of 100
Topics in C Programming
Q.31 Medium Control Flow
What does the following code segment do?
int i = 0;
do {
printf("%d ", i);
} while(++i < 3);
A Prints: 0 1 2
B Prints: 1 2 3
C Prints nothing
D Infinite loop
Correct Answer:  A. Prints: 0 1 2
EXPLANATION

do-while executes body first (prints 0), then checks ++i < 3. Loop continues for i=1,2. When i=3, condition fails. Output: 0 1 2

Take Test
Q.32 Medium Control Flow
What is the key distinction between if-else and switch statements in terms of evaluation?
A if-else is faster than switch
B if-else evaluates conditions, switch uses jump table for integral constants
C switch can handle float types but if-else cannot
D if-else allows multiple conditions, switch allows only one
Correct Answer:  B. if-else evaluates conditions, switch uses jump table for integral constants
EXPLANATION

switch typically uses jump tables for efficient multi-way branching with integral values, while if-else evaluates boolean expressions sequentially.

Take Test
Q.33 Medium Control Flow
Consider the code:
int x = 0;
while(1) {
if(++x > 3) break;
printf("%d ", x);
}
What is the output?
A 0 1 2
B 1 2 3
C 1 2
D Infinite loop with no output
Correct Answer:  B. 1 2 3
EXPLANATION

Pre-increment ++x happens first. When x becomes 4, condition is true and loop breaks. Values printed: x=1,2,3 (before x reaches 4).

Take Test
Q.34 Easy Control Flow
Which statement is true about the goto statement in modern C programming?
A It is completely removed from C standards
B It is legal but generally discouraged for code clarity
C It is mandatory for error handling
D It automatically optimizes loop performance
Correct Answer:  B. It is legal but generally discouraged for code clarity
EXPLANATION

goto is valid in C but discouraged in modern programming as it reduces code readability. However, it has legitimate uses in cleanup code and error handling.

Take Test
Q.35 Medium Control Flow
What happens when you use break in a nested loop structure?
A Breaks both inner and outer loop
B Breaks only the immediate (inner) loop
C Breaks all loops in the program
D Causes compilation error
Correct Answer:  B. Breaks only the immediate (inner) loop
EXPLANATION

break statement exits only the innermost loop it's in. To break outer loop, you need additional logic or goto statement.

Take Test
Q.36 Medium Control Flow
Analyze: What is printed by this code?
for(int i = 1; i
A 1 22 333
B 1 2 3
C 123 123 123
D 1 22 333 (with spaces)
Correct Answer:  D. 1 22 333 (with spaces)
EXPLANATION

Outer loop: i=1,2,3. Inner loop repeats i times. When i=1: print '1' once. i=2: print '2' twice. i=3: print '3' thrice. Each iteration separated by space.

Take Test
Q.37 Medium Control Flow
Which of the following is a valid use of the switch statement in C?
A switch(1.5) { case 1.5: break; }
B switch("hello") { case "hello": break; }
C switch(x) { case 1: case 2: case 3: printf("A"); }
D switch(x > 5) { case true: break; }
Correct Answer:  C. switch(x) { case 1: case 2: case 3: printf("A"); }
EXPLANATION

Switch works with integral types only. Multiple case labels before statements (fall-through) is valid. Strings and floats are not allowed.

Take Test
Q.38 Easy Control Flow
In the ternary operator expression (condition ? expr1 : expr2), if condition is true, which expression evaluates?
A Both expr1 and expr2
B Only expr1
C Only expr2
D Neither, condition is returned
Correct Answer:  B. Only expr1
EXPLANATION

Ternary operator is short-circuit. If condition is true, expr1 evaluates and expr2 is skipped. If false, expr2 evaluates and expr1 is skipped.

Take Test
Q.39 Medium Control Flow
What does the following code segment accomplish?
int i = 0;
while(i < 5) {
if(i == 2) {
i++;
continue;
}
printf("%d ", i);
i++;
}
A Prints: 0 1 2 3 4
B Prints: 0 1 3 4
C Prints: 0 1
D Infinite loop
Correct Answer:  B. Prints: 0 1 3 4
EXPLANATION

When i==2, continue skips printf but still increments i. So 2 is not printed. Output: 0 1 3 4

Take Test
Q.40 Medium Control Flow
Consider the code:
int x = 5;
if(x > 3)
if(x > 10)
printf("A");
else
printf("B");
Which statement best describes the output?
A Prints 'A' because x > 3
B Prints 'B' due to else binding to inner if
C Prints nothing
D Compilation error due to ambiguity
Correct Answer:  B. Prints 'B' due to else binding to inner if
EXPLANATION

The else binds to the nearest if statement (inner if). Since x=5 is not > 10, the inner condition fails and else executes, printing 'B'.

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