Question 10
Back to Exercise
What is the output of the following C program?
#include <stdio.h>
int main(void) {
int a = 7;
if (a = 0, a + 1)
printf("true %d\n", a);
else
printf("false %d\n", a);
return 0;
}
- A true 0 Correct
- B false 0
- C true 7
- D false 7
Correct Answer: Option A
The comma operator evaluates its left side (a = 0) and then yields its right side (a + 1 = 1). The condition is 1, so the true branch runs with a now 0.
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!