What is printed by this C code: int c = 0; for (int i = 0; i < 3; i++) for (int j = 0; j < 3; j++) { if (j == 1) break; c++; } printf(“%d”, c);?
Correct answer C. 3
Explanation
break leaves only the innermost enclosing loop. For every i, the inner loop runs once with j = 0 (c is incremented), then j becomes 1 and break ends the inner loop, while the outer loop continues. Three outer passes give c = 3. Answer 1 assumes break exits both loops; leaving nested loops at once needs a flag, a return or a goto.
Answer checked How we write and check questions
Discussion