ProgrammingHardProduct-company MCQ pattern

What is printed?

What is printed?
int a[] = {5, 10, 15};
int *p = a;
int x = *p++;
int y = (*p)++;
int z = *++p;
printf("%d %d %d %d", x, y, z, a[1]);
  1. A. 5 11 15 11
  2. B. 6 10 15 10
  3. C. 5 10 11 11
  4. D. 5 10 15 11

Correct answer: D. 5 10 15 11

*p++ reads a[0] = 5 and moves p to a[1]. (*p)++ yields 10 and then makes a[1] 11, with p unchanged. *++p moves p to a[2] and reads 15. So 5 10 15 and a[1] = 11.

More C Programming questions

Exams that ask this topic