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.82Medium
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.83Medium
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.84Easy
What is the purpose of the ternary operator (? :) in C?
Answer: B
The ternary operator (condition ? true_value : false_value) is a concise alternative to if-else for simple conditional assignments.
Q.85Medium
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.
Advertisement
Q.86Medium
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'.
Q.87Medium
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.88Hard
What is the output?
for(int i = 0; i < 3; i++)
for(int j = 0; j < 3; j++)
if(i == j) continue;
printf("Done");
Answer: A
continue only skips the current iteration of innermost loop, not the outer. After both loops complete, 'Done' is printed once.
Q.89Medium
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.90Hard
What will this code print?
int x = 0;
while(x < 3) {
printf("%d ", x++);
if(x == 2) continue;
printf("X ");
}
Answer: D
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.
Q.91Easy
Which statement is true about the goto statement in modern C programming practices?
Answer: C
goto is legal in C but discouraged as it can create hard-to-follow code paths. It's acceptable in limited contexts like error handling.
Q.92Hard
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);
}
}
Answer: A
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.
Q.93Medium
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.94Medium
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.95Easy
What is the primary difference between 'break' and 'continue' statements in C loops?
Answer: A
break statement terminates the loop completely, whereas continue statement skips the remaining statements in the current iteration and moves to the next iteration of the loop.
Q.96Easy
Consider the following code snippet:
int x = 5;
do {
printf("%d ", x);
x--;
} while(x > 0);
What will be the output?
Answer: A
The do-while loop executes at least once. x starts at 5, prints 5, decrements to 4, and continues while x > 0. Loop executes for x = 5,4,3,2,1 and exits when x becomes 0.
Q.97Medium
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.98Medium
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.99Medium
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.
Q.100Hard
Consider the code:
int sum = 0;
for(int i = 1; i <= 10; i++) {
if(i % 2 == 0) continue;
sum += i;
}
printf("%d", sum);
What will be printed?
Answer: A
The loop adds only odd numbers (1,3,5,7,9) due to the continue statement when i is even. Sum = 1+3+5+7+9 = 25.