ProgrammingModerateTCS NQT · Accenture

What is printed?

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

Correct answer: A. 7

The conditional operator groups to the right, so the inner test 2 > 1 chooses 7 and the outer test 5 > 3 keeps that result.

More C Programming questions

Exams that ask this topic