ProgrammingHard

unsigned n = 5; int c = 0; while (n-- > 0) c++; printf("%d", c); What is printed?

  1. A. 4
  2. B. 5
  3. C. 6
  4. D. 0

Correct answer: B. 5

The unsigned n goes 5, 4, 3, 2, 1 and each test passes before the decrement. When n is 0 the test fails, so c is 5.

More C Programming questions

Exams that ask this topic