Multiple choice

What does the statement printf(“%d”,10?0?5:11:12); print?

  1. 10

  2. 0

  3. 12

  4. 11

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

The ternary operator is right-associative. 10 ? (0 ? 5 : 11) : 12. Since 10 is true, it evaluates (0 ? 5 : 11). Since 0 is false, it returns 11.