ProgrammingVery hardWipro · Accenture · Capgemini pattern

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 x = 7; int *p = &x; int old = (*p)++; int y = old + *p; printf("%d %d", x, y); return 0; }

  1. A. 8 14
  2. B. 7 14
  3. C. 8 15
  4. D. 8 16

Correct answer: C. 8 15

(*p)++ yields the old value 7 (stored in old) and then increments x to 8; the later *p reads the now-updated value 8 as a separate statement (no undefined ordering here); y = 7 + 8 = 15.

More C Programming questions

Exams that ask this topic