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[] = {3, 33, 29, 16, 3, 16, 14, 2, 33}; int *p = a + 6; printf("%d %d %d", *(p + 1) - *p, p[-1], (int)(&a[8] - p)); return 0; }

  1. A. -12 16 2
  2. B. -12 16 8
  3. C. 12 16 2
  4. D. -12 14 2

Correct answer: A. -12 16 2

p points at a[6]=14; *(p+1) is a[7]=2; p[-1] is a[5]=16; pointer subtraction counts elements, not bytes: 8−6 = 2.

More C Programming questions

Exams that ask this topic