ProgrammingVery hardTCS NQT · Infosys · Product Company SDE

What is the output of this C program (assume a typical 64-bit platform: int 32 bits, long and pointers 64 bits)? #include <stdio.h> int main(void) { int a[] = {5, 37, 35, 23, 22, 20, 33, 24, 36}; int *p = a + 4; printf("%d %d %d", *(p + 1) - *p, p[-1], (int)(&a[8] - p)); return 0; }

  1. A. -2 23 4
  2. B. -2 22 4
  3. C. -2 23 16
  4. D. 42 35 5

Correct answer: A. -2 23 4

p points at a[4]=22; *(p+1) is a[5]=20; p[-1] is a[3]=23; pointer subtraction counts elements, not bytes: 8−4 = 4.

More C Programming questions

Exams that ask this topic