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, double 8 bytes, structs aligned to their widest member with no packing pragma)? #include <stdio.h> int main(void) { int a = 5, b = 2, c = 3; int r = a > b ? (b > c ? b : c) : a; printf("%d", r); return 0; }

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

Correct answer: B. 3

a>b (5>2) is true, so we evaluate b>c (2>3), which is false, selecting c=3.

More C Programming questions

Exams that ask this topic