All mock tests are FREE till 31 December — register to save your progress

What is the output? int i, j, x = 0; for (i = 0; i < 5; ++i) for (j = 0; j < i; ++j) { x += (i + j − 1); break; } printf("%d", x);

Pick an option to check yourself, or open the answer below.

Show answer & explanation

Correct answer: A. 6

Explanation

The inner loop runs only for j = 0 before breaking, adding i − 1 for i = 1 to 4: 0 + 1 + 2 + 3 = 6.

More Programming Languages and Computer Graphics questions