GATE Computer ScienceModerateGATE CS (PYQ pattern)

#include <stdio.h> int main() { int a[5] = {10, 20, 30, 40, 50}; int *p = (int *)(&a + 1); printf("%d %d", *(a + 1), *(p - 2)); } What is printed?

  1. A. 20 30
  2. B. 20 40
  3. C. 30 40
  4. D. 20 50

Correct answer: B. 20 40

&a has type int(*)[5], so &a + 1 points just past the whole array. p - 2 is then a[3] = 40, and *(a+1) = 20.

More Programming and Data Structures (GATE) questions

Exams that ask this topic