ProgrammingHardHCL · Tech Mahindra pattern

What is printed?

What is printed?
int arr[3] = {1, 2, 3};
int (*p)[3] = &arr;
printf("%d %d", (*p)[1], *(*p + 2));
  1. A. 2 3
  2. B. Compilation error: incompatible pointer types
  3. C. 1 2
  4. D. 2 2

Correct answer: A. 2 3

&arr has type int(*)[3], a pointer to the whole array, matching p's declared type. (*p) dereferences back to the array itself, so (*p)[1] = arr[1] = 2, and *(*p+2) = arr[2] = 3.

More C Programming questions

Exams that ask this topic