ProgrammingHardTCS NQT · Infosys
int x = 5; printf("%d", x > 3 ? x - 3 : x + 3); What is printed?
- A. 8
- B. 3
- C. 5
- D. 2
Correct answer: D. 2
x > 3 is true, so the conditional yields x - 3 = 2. The conditional operator has lower precedence than comparison but higher than assignment.
More C Programming questions
- What does printf("%d", (4, 5) 2) print?
- int x = 0, y = 1; What does printf("%d", !x == y) print?
- printf("%d %d", 1 < 2 < 3, 3 > 2 > 1); What is printed?
- What does printf("%d", -5 % 3) print?
- double x = 7 / 2 2.0; printf("%g", x); What is printed?
- unsigned char c = 0x0F; printf("%d", (unsigned char)~c); What is printed?