ProgrammingModerateAccenture · Capgemini pattern

What is printed?

What is printed?
int a[5] = {1, 2, 3, 4, 5};
int *p = a + 4;
while (p > a)
    printf("%d", *--p);
  1. A. 54321
  2. B. 5432
  3. C. 4321
  4. D. 321

Correct answer: C. 4321

p starts at a[4], but *--p decrements BEFORE reading, so the first value printed is a[3] = 4. The loop continues while p > a; once p reaches a (after printing a[0] = 1) the test fails. a[4] = 5 is never printed.

More C Programming questions

Exams that ask this topic