Practice mode C Language

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.

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.