ProgrammingHardTCS NQT · Accenture

What is printed?

What is printed?
#include <stdio.h>
int main(void) {
    printf("%d", 1 ? 2 : 3 ? 4 : 5);
}
  1. A. 4
  2. B. 3
  3. C. 2
  4. D. 5

Correct answer: C. 2

The conditional operator groups to the right, but since the first test is true, the result is 2 and the rest is not evaluated.

More C Programming questions

Exams that ask this topic