ProgrammingHardIBM · Deloitte · 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, double 8 bytes, structs aligned to their widest member with no packing pragma)? #include <stdio.h> int main(void) { int a[4] = {1, 2, 3, 4}; int *p = a + 1; printf("%d %d", p[1], *(a + 3) - *p); return 0; }

  1. A. 4 1
  2. B. 3 2
  3. C. 4 2
  4. D. 3 1

Correct answer: B. 3 2

p points at a[1]=2, so p[1] is a[2]=3; *(a+3) is a[3]=4, and 4 - *p(=2) = 2. Together: 3 2.

More C Programming questions

Exams that ask this topic