ProgrammingModerateHCL · Tech Mahindra pattern

What is printed?

What is printed?
int n = 5;
while (n-- > 2)
    printf("%d", n);
printf(" %d", n);
  1. A. 432 1
  2. B. 543 2
  3. C. 43 1
  4. D. 432 2

Correct answer: A. 432 1

Each test compares the old n, then decrements: 5 > 2 (prints 4), 4 > 2 (prints 3), 3 > 2 (prints 2), 2 > 2 fails but still decrements n to 1. So 432, then 1.

More C Programming questions

Exams that ask this topic