What is the output of this complex nested control flow?
int x = 1, y = 2;
if (x < y) {
x++; y--;
if (x == y)
printf("Equal");
else
printf("NotEqual");
}
Answer: A
x=1, y=2. Since 1 < 2, x becomes 2 and y becomes 1. Now x != y, but after operations x=2, y=1. Wait: x++ makes x=2, y-- makes y=1. So x==y is false, printing 'NotEqual'. Rechecking: 1 < 2 is true, so enter if. x becomes 2, y becomes 1. 2 == 1 is false, so else executes, printing 'NotEqual'.
Q.202Easy
In C, which control flow statement is used to terminate a loop prematurely?
Answer: A
The 'break' statement is used to exit or terminate a loop immediately. 'continue' skips the current iteration, 'exit' terminates the entire program.
Q.203Medium
Which of the following is NOT a valid use of the goto statement in C?
Answer: C
goto cannot jump across function boundaries. It can only jump within the same function to a labeled statement either forward or backward.
Q.204Easy
What is the primary difference between a while loop and a do-while loop?
Answer: A
A do-while loop executes the body at least once before checking the condition. A while loop checks the condition first, so it may not execute at all.
Q.205Easy
In a nested loop structure, which statement will skip only the inner loop's current iteration?
Answer: B
The 'continue' statement skips the remaining statements of the current iteration and moves to the next iteration. In nested loops, it affects only the innermost loop.
Advertisement
Q.206Medium
Consider a switch statement with multiple cases. If a case matches and break is omitted, what happens?
Answer: B
Without a break statement, execution continues to the next case (fall-through behavior). This is a common source of bugs if not intentional.
Q.207Medium
What will be the behavior of a for loop with an empty body and no statements inside braces?
Answer: C
A for loop with an empty body is valid syntax in C. The loop executes for the specified iterations but performs no operations in each iteration.
Q.208Easy
In the expression (x > 5) ? (y = 10) : (y = 20), what does y equal if x is 3?
Answer: B
The ternary operator evaluates the condition (x > 5). Since 3 is not greater than 5, the expression evaluates to false, and the false part executes, setting y to 20.
Q.209Easy
Which control flow structure allows execution of code only if a certain condition is met?
Answer: B
The if statement executes a block of code conditionally. Loops repeat code, and switch cases are for multi-way branching based on a single expression.
Q.210Medium
What is the output of executing break in a nested loop context?
Answer: B
The break statement exits only the innermost loop it is in. To exit multiple nested loops, you need multiple break statements or use goto.
Q.211Easy
In a switch statement, which keyword provides a default case if no cases match?
Answer: B
The 'default' keyword in a switch statement provides code to execute when no case values match the switch expression.
Q.212Easy
What is the correct syntax for a for loop that iterates from 0 to 9?
Answer: B
for(int i=0; i<10; i++) correctly iterates from 0 to 9 (10 iterations total). Using i<=10 would iterate 11 times, and starting from 1 would skip 0.
Q.213Medium
Which of the following correctly uses the conditional (ternary) operator?
Answer: B
The correct syntax is (condition) ? (value_if_true) : (value_if_false). The condition comes first, followed by ? and then the true and false values separated by :.
Q.214Medium
How many times will a do-while loop execute if the condition is initially false?
Answer: B
A do-while loop executes the body at least once before checking the condition. Even if the condition is false, the body executes one time.
Q.215Medium
In control flow, which statement is used to explicitly exit from a program?
Answer: B
The exit() function terminates the entire program and returns control to the operating system. break exits loops, and return exits functions.
Q.216Hard
What happens when continue is used in a for loop with a post-increment expression?
Answer: B
When continue is executed in a for loop, the post-increment (i++) still executes before the condition is checked again. Only the body statements after continue are skipped.
Q.217Easy
Which control structure allows checking multiple conditions in sequence using else-if?
Answer: C
The if-else-if chain allows testing multiple different conditions sequentially. switch is used for a single expression with multiple values.
Q.218Medium
In a switch statement, case values must be of which type?
Answer: B
Switch case values must be constant integral expressions (int, char, enum). Floating-point values and strings (in C89/C90) are not allowed.
Q.219Hard
What is the effect of using multiple break statements in nested loops?
Answer: C
Each break statement exits only its immediately enclosing loop. To exit multiple nested loops, you need one break for each level you want to exit.
Q.220Medium
What is the scope of a variable declared in the initialization section of a for loop?
Answer: C
Variables declared in a for loop's initialization (e.g., for(int i=0; ...)) have block scope limited to that loop. They are not accessible outside the loop.