Multiple choice

int x = 0; for (x=1; x<4; x++); printf(x=%dn, x); What will be the output of the sample code given above?

  1. x = 0

  2. x = 1

  3. x = 3

  4. x = 4

  5. x = 5

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

The for loop increments x until x<4 becomes false. The loop runs for x=1, 2, 3, then when x becomes 4, the condition fails. The semicolon after for(x=1; x<4; x++); makes the loop body empty, so only the increment happens. After loop exit, x equals 4, which printf displays.