Practice mode C Language

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.

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.