Which statement best describes the difference between break and continue?
Answer: A
break completely exits/terminates the loop. continue skips the rest of current iteration and jumps to the next iteration.
Q.22Easy
What value does the ternary operator return?
int result = (5 > 3) ? 10 : 20;
Answer: C
The condition (5 > 3) is true, so the ternary operator evaluates and returns the true expression value: 10.
Q.23Easy
Which of the following control flow statements will cause a compilation error in C?
Answer: A
break and continue statements can only be used within loops or switch statements. Using break outside these constructs results in a compilation error.
Q.24Easy
What is the primary difference between while and do-while loops?
Answer: B
do-while loop checks the condition after executing the loop body, ensuring at least one execution. while loop checks before executing.
Q.25Easy
In a switch statement, if a case label is missing the break statement, what occurs?
Answer: C
Missing break causes fall-through behavior where execution continues to the next case label until a break or end of switch is encountered.
Advertisement
Q.26Easy
Which control flow statement allows jumping to a labeled location in C?
Answer: B
goto statement allows unconditional jump to a labeled location. Though generally discouraged, it's valid in C and sometimes used for error handling.
Q.27Easy
In the ternary operator expression (condition ? expr1 : expr2), if condition is true, which expression evaluates?
Answer: B
Ternary operator is short-circuit. If condition is true, expr1 evaluates and expr2 is skipped. If false, expr2 evaluates and expr1 is skipped.
Q.28Easy
Which statement is true about the goto statement in modern C programming?
Answer: B
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.
Q.29Easy
In a for loop for(int i = 0; i < 5; i++), at what point does the increment happen?
Answer: B
For loop order: initialization → check condition → execute body → increment → repeat from condition check.
Q.30Easy
In a nested loop structure, which statement is used to skip the current iteration of the innermost loop only?
Answer: B
continue skips the current iteration of the innermost loop and moves to the next iteration, while break exits the loop entirely.
Q.31Easy
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.32Easy
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.33Easy
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.34Easy
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.35Easy
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.36Easy
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.