Home Subjects C Programming Control Flow

C Programming
Control Flow

C language from basics to advanced placement prep

52 Q 10 Topics Take Test
Advertisement
Difficulty: All Easy Medium Hard 1–10 of 52
Topics in C Programming
Q.1 Medium Control Flow
Which of the following statements about the switch-case construct is INCORRECT?
A The default case is mandatory in every switch statement
B Each case must end with a break statement to prevent fall-through
C Multiple cases can have the same code block if break is omitted
D The switch expression is evaluated only once
Correct Answer:  A. The default case is mandatory in every switch statement
EXPLANATION

The default case is optional in a switch statement. It executes when no case matches, but it is not mandatory. All other statements are correct properties of switch-case.

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

When i=0: prints 0. When i=1: prints 1. When i=2: continue skips printf. When i=3: break terminates the loop. Output is '0 1'.

Test
Q.3 Medium Control Flow
In nested loops, if an inner loop contains a break statement, what happens?
A Only the inner loop terminates; the outer loop continues
B Both inner and outer loops terminate
C The entire program terminates
D The break statement is ignored in nested loops
Correct Answer:  A. Only the inner loop terminates; the outer loop continues
EXPLANATION

The break statement only exits the innermost loop that contains it. It does not affect the outer loop's execution. The outer loop will continue its iterations normally.

Test
Q.4 Medium Control Flow
In a for loop with multiple break statements in different conditions, which break will be executed?
A Only the first break encountered
B All break statements execute
C The break statement whose condition is true
D None of them execute unless the loop condition fails
Correct Answer:  C. The break statement whose condition is true
EXPLANATION

Only the break statement whose associated if condition evaluates to true will be executed, exiting the loop immediately.

Test
Q.5 Medium Control Flow
What is the output of this code?
char ch = 'B';
switch(ch) {
case 'A':
case 'B':
case 'C': printf("Vowel");
break;
default: printf("Consonant");
}
A Vowel
B Consonant
C No output
D Compilation error
Correct Answer:  A. Vowel
EXPLANATION

ch='B' matches case 'B', which has no statements. Execution falls through to case 'C' which has no statements, then prints 'Vowel' and breaks.

Test
Q.6 Medium Control Flow
In C programming, what is the difference between break in a loop and break in a switch statement?
A There is no difference
B break in switch exits all nested structures, break in loop exits only the loop
C break in loop exits the loop, break in switch exits only the current case
D break in switch works only with integers, break in loop works with all types
Correct Answer:  C. break in loop exits the loop, break in switch exits only the current case
EXPLANATION

Both break statements exit their immediate enclosing structure. In loops, break exits the loop; in switch, break exits the switch block.

Test
Q.7 Medium Control Flow
Which control structure would be most efficient to validate if a number is within one of several specific values?
A Multiple if-else if chains
B Nested if statements
C switch statement
D do-while loop with break
Correct Answer:  C. switch statement
EXPLANATION

switch statement is optimized for multiple discrete value checks and is more readable than chained if-else statements.

Test
Q.8 Medium Control Flow
What will be the output of this code?
int n = 5;
switch(n) {
case 4: printf("Four");
case 5: printf("Five");
case 6: printf("Six");
break;
default: printf("Other");
}
A Five
B FiveSix
C FourFiveSix
D Other
Correct Answer:  B. FiveSix
EXPLANATION

n=5 matches case 5. Without break, it falls through to case 6 before encountering break. Prints 'FiveSix'.

Test
Q.9 Medium Control Flow
How many times will the loop execute?
int i = 0;
while(i++ < 5) {
printf("%d ", i);
}
A 4 times
B 5 times
C 6 times
D Infinite loop
Correct Answer:  B. 5 times
EXPLANATION

i++ returns value before incrementing. Condition checks: 0<5(T), 1<5(T), 2<5(T), 3<5(T), 4<5(T), 5<5(F). Loop runs 5 times.

Test
Q.10 Medium Control Flow
What will this code output?
for(int i = 1; i
A 1\n12\n123
B 123\n123\n123
C 1\n2\n3
D 111\n222\n333
Correct Answer:  A. 1\n12\n123
EXPLANATION

Nested loop: outer loop runs 3 times, inner loop runs i times. Prints 1, then 12, then 123 on separate lines.

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