ProgrammingVery hardGATE CS · Product company OA

What is printed?

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

Correct answer: A. 50 20 3

&a has type int (*)[5], so &a + 1 jumps over the whole array to one past its end; p − 1 is a[4] = 50. q is &a[2], so q − 1 is a[1] = 20, and p − q = 5 − 2 = 3. '10' treats &a + 1 like a + 1.

More C Programming questions

Exams that ask this topic