What is the output of the following code?
int x = 5;
if(x > 3)
if(x < 10)
printf("Pass");
else
printf("Fail");
Answer: A
The inner if condition (x < 10) is true, so 'Pass' is printed. The else is associated with the inner if, not the outer one.
Q.262Easy
Which looping construct in C allows initialization, condition, and increment to be placed in a single line?
Answer: C
The for loop syntax is for(init; condition; increment) allowing all three components in one statement.
Q.263Easy
In which scenario would a do-while loop be preferred over a while loop?
Answer: A
do-while executes the body first, then checks the condition, ensuring at least one execution.
Q.264Medium
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.265Medium
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.
Advertisement
Q.266Medium
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.267Easy
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.268Medium
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.269Medium
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.270Medium
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.271Hard
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.272Medium
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.273Hard
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.274Easy
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.275Hard
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.276Medium
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.277Medium
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.278Easy
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.279Easy
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.280Medium
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.