ProgrammingHardCompetitive coding (CP) · C internals

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 = 10; printf("%d", x > 5 ? (x > 8 ? 1 : 2) : 3); return 0; }

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

Correct answer: B. 1

The ternary nests on the true branch: x>5 is true, and within it x>8 is also true, so the result is 1.

More C Programming questions

Exams that ask this topic