Question 3
Back to Exercise
What is the output of the following C program?
#include <stdio.h>
int main(void) {
int a, b, c;
a = b = c = 4;
a += b -= c *= 2;
printf("%d %d %d\n", a, b, c);
return 0;
}
- A 0 -4 8 Correct
- B 8 4 8
- C 4 0 8
- D -4 -4 8
Correct Answer: Option A
Compound assignments are right-associative: c *= 2 makes c 8, b -= 8 makes b −4, and a += -4 makes a 0. Each variable is modified once, so this is well-defined.
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!