ProgrammingHardWipro · Cognizant pattern

What is printed?

What is printed?
int a[3] = {1,2,3};
int *p = a;
int *arrp[1] = {p};
int **pp = arrp;
(*pp)[1] = 99;
printf("%d %d %d", a[0], a[1], a[2]);
  1. A. 1 2 3
  2. B. 1 99 3
  3. C. 99 2 3
  4. D. 1 2 99

Correct answer: B. 1 99 3

*pp dereferences pp to get arrp[0], which is p (pointing at a[0]); indexing that with [1] reaches a[1], setting it to 99.

More C Programming questions

Exams that ask this topic