What is printed by this C code: int i = 5; while (i– > 0) printf(“%d”, i);?
Correct answer B. 43210
Explanation
The test i-- > 0 compares the old value of i and then decrements it. The first test compares 5 > 0 (true) and i becomes 4, so 4 is printed. This continues until the test compares 0 > 0, which is false, though i still becomes -1. The printed sequence is 43210. 54321 would need the decrement after the printf, as in a for loop with i-- in the update part.
Answer checked How we write and check questions
Discussion