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[] = {15, 38, 22, 5, 30, 11, 38, 22}; int *p = a + 3; printf("%d %d %d", *(p + 1) - *p, p[-1], (int)(&a[7] - p)); return 0; }

  1. A. 35 38 5
  2. B. 25 22 16
  3. C. 25 22 4
  4. D. -25 22 4

Correct answer: C. 25 22 4

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

More C Programming questions

Exams that ask this topic