Question 8
Back to Exercise
What is the output of the following C program?
#include <stdio.h>
int main(void) {
int a = 5, b = 8;
int r = a > b ? a : b > 6 ? b * 2 : b;
printf("%d\n", r);
return 0;
}
- A 16 Correct
- B 8
- C 5
- D 10
Correct Answer: Option A
?: is right-associative: a > b ? a : (b > 6 ? b * 2 : b). a > b is false, b > 6 is true, so the result is 16.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!