← Bitkernel Interview Insights
I almost said infinite loop because I skimmed it too fast and read `n = 0` as `n == 0`.
First, carefully parse the loop syntax, noting that the condition is an assignment (n = 0) rather than a comparison. Then, evaluate the assignment's value (0, which is false) to determine that the loop body never executes. Finally, explain the initialization and increment expressions to show they are irrelevant to the outcome.
Pro tip: Point out that this is a classic trap question: many candidates mistake '=' for '==' and assume the loop runs. By explicitly stating that the assignment yields 0 (false), you demonstrate precise C semantics and attention to detail.
Identify the three parts of the for loop: initialization (m = 0, n = -1), condition (n = 0), and increment (m++, n++). Note that the condition uses a single equals sign, which is assignment, not comparison.
The condition is an assignment expression: n = 0. This assigns 0 to n and evaluates to 0. In C, 0 is false, so the loop condition is false from the start.
Since the condition is false before the first iteration, the loop body never executes. The initialization and increment expressions are evaluated but do not affect the loop's execution count.
The increment part (m++, n++) and the extra n++ in the body are never reached because the loop body doesn't run. Mention that even if the condition were true, the increment would execute after each iteration.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.