ProgrammingModerateTCS NQT · Wipro

What is printed?

What is printed?
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);
  1. A. 6
  2. B. 9
  3. C. 1
  4. D. 3

Correct answer: D. 3

break leaves only the innermost loop. Each outer pass counts j = 0 once and breaks at j = 1, so c = 3. '1' assumes break ends both loops.

More C Programming questions

Exams that ask this topic