ProgrammingHardAccenture · Capgemini · C

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 = 5; int y = x++ + 10; int z = ++x * 2; printf("%d %d %d", x, y, z); return 0; }

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

Correct answer: D. 7 15 14

y = x++ + 10 uses the old x=5 then increments x to 6, so y=15; z = ++x * 2 increments x to 7 first, then 7*2=14.

More C Programming questions

Exams that ask this topic