ProgrammingHardTCS 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 = 7, b = 3; int r = (a > b && ++a > 0) ? a : b; printf("%d %d", r, a); return 0; }

  1. A. 9 8
  2. B. 8 7
  3. C. 3 8
  4. D. 8 8

Correct answer: D. 8 8

&& short-circuits: ++a runs only if a > b (7 > 3 is true). So a = 8 and r = 8.

More C Programming questions

Exams that ask this topic