ProgrammingVery hardInfosys · C · Advanced

What is printed?

What is printed?
int a[] = {5, 10, 15, 20};
int *p = a;
*p++ += 3;
(*p)++;
++*p;
*++p *= 2;
printf("%d %d %d %d %d", a[0], a[1], a[2], a[3], (int)(p - a));
  1. A. 8 11 30 20 2
  2. B. 8 12 30 20 2
  3. C. 8 12 15 40 3
  4. D. 5 13 30 20 2

Correct answer: B. 8 12 30 20 2

*p++ += 3 raises a[0] to 8 and moves p; (*p)++ and ++*p take a[1] to 12; *++p advances to a[2] and doubles it to 30, leaving p - a = 2.

More C Programming questions

Exams that ask this topic