GATE Computer ScienceVery hardGATE CS (PYQ pattern)

int a[] = {5, 6, 7, 8}; int *p = a; *p++ += 2; (*p)++; *++p += 10; ++*p; What are a[0], a[1], a[2], a[3] and p - a after these statements?

  1. A. 7, 7, 18, 8 and 3
  2. B. 7, 8, 17, 8 and 2
  3. C. 8, 7, 17, 8 and 2
  4. D. 7, 7, 18, 8 and 2

Correct answer: D. 7, 7, 18, 8 and 2

*p++ += 2 makes a[0] = 7 and moves p to a[1]. (*p)++ makes a[1] = 7. *++p moves p to a[2] and adds 10 (17); ++*p makes 18. p - a = 2.

More Programming and Data Structures (GATE) questions

Exams that ask this topic