Evaluate C for-loop execution count
BitkernelSoftware Engineer · Online AssessmentLast updated
This question evaluates understanding of C expression evaluation and control-flow semantics, focusing on how assignment expressions interact with loop conditions and variable updates.
In C, variables m and n are both of type int. Consider the following code:
int m, n;
for (m = 0, n = -1; n = 0; m++, n++)
n++;
In standard C semantics (where = is assignment, not comparison), how many times does the loop body (n++ inside the loop) execute?
Options:
- A. The loop body executes 0 times
- B. The loop body executes 1 time
- C. The loop is infinite
- D. There is a runtime error
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.