ProgrammingModerateTCS NQT · C

What is printed?

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

Correct answer: A. 30 10 2

p points to a[1]; *(p+1) = a[2] = 30, p[-1] = a[0] = 10, and the pointer difference &a[3] - p is 2 elements.

More C Programming questions

Exams that ask this topic