What is the output?
int x = 10;
while(x-- > 5) {
printf("%d ", x);
}
Answer: C
x-- returns the value before decrementing. Loop runs while value > 5: prints 9,8,7,6 (when x becomes 5, condition fails).
Q.42Medium
Which of the following statements about switch case is TRUE?
Answer: C
Without break, execution falls through to the next case. Default can be anywhere, and modern C allows switch with other types.
Q.43Medium
What will this code output?
for(int i = 1; i <= 3; i++) {
for(int j = 1; j <= i; j++) {
printf("%d", j);
}
printf("\n");
}
Answer: A
Nested loop: outer loop runs 3 times, inner loop runs i times. Prints 1, then 12, then 123 on separate lines.
Q.44Medium
How many times will the loop execute?
int i = 0;
while(i++ < 5) {
printf("%d ", i);
}
Answer: B
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.
Q.45Medium
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");
}
Answer: B
n=5 matches case 5. Without break, it falls through to case 6 before encountering break. Prints 'FiveSix'.
Advertisement
Q.46Medium
Which control structure would be most efficient to validate if a number is within one of several specific values?
Answer: C
switch statement is optimized for multiple discrete value checks and is more readable than chained if-else statements.
Q.47Medium
In C programming, what is the difference between break in a loop and break in a switch statement?
Answer: C
Both break statements exit their immediate enclosing structure. In loops, break exits the loop; in switch, break exits the switch block.
Q.48Medium
What is the output of this code?
char ch = 'B';
switch(ch) {
case 'A':
case 'B':
case 'C': printf("Vowel");
break;
default: printf("Consonant");
}
Answer: A
ch='B' matches case 'B', which has no statements. Execution falls through to case 'C' which has no statements, then prints 'Vowel' and breaks.
Q.49Medium
In a for loop with multiple break statements in different conditions, which break will be executed?
Answer: C
Only the break statement whose associated if condition evaluates to true will be executed, exiting the loop immediately.
Q.50Medium
In nested loops, if an inner loop contains a break statement, what happens?
Answer: A
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.
Q.51Medium
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?
Answer: A
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'.
Q.52Medium
Which of the following statements about the switch-case construct is INCORRECT?
Answer: A
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.