C | Operators | Question 23
Predict the output of following program?
# include <stdio.h> int main() { int x = 10; int y = 20; x += y += 10; printf (" %d %d", x, y); return 0; } |
chevron_right
filter_none
(A) 40 20
(B) 40 30
(C) 30 30
(D) 30 40
Answer: (B)
Explanation: The main statement in question is “x += y += 10”. Since there are two += operators in the statement, associativity comes into the picture. Associativity of compound assignment operators is right to left, so the expression is evaluated as x += (y += 10).
Quiz of this Question
Recommended Posts:
- Operators in C | Set 2 (Relational and Logical Operators)
- C | Operators | Question 27
- C | Operators | Question 26
- C | Operators | Question 18
- C | Operators | Question 17
- C | Operators | Question 15
- C | Operators | Question 13
- C | Operators | Question 21
- C | Operators | Question 22
- C | Operators | Question 27
- C | Operators | Question 27
- C | Operators | Question 26
- C | Operators | Question 11
- C | Operators | Question 24
- C | Operators | Question 12



