int a = 5;
int b;
b = a++ + --a + a++;
printf("%d", b);
What is the output?
Explanation
Solution
The correct answer is (b) 15.
Part 1 (a++): Uses current value 5, then a becomes 6.
Part 2 (−−a): a (currently 6) is decremented first, becoming 5. Value used is 5.
Part 3 (a++): Uses current value 5, then a becomes 6.
Total for b: 5+5+5=15.
Explanation
Solution
The correct answer is (b) 15.
Part 1 (a++): Uses current value 5, then a becomes 6.
Part 2 (−−a): a (currently 6) is decremented first, becoming 5. Value used is 5.
Part 3 (a++): Uses current value 5, then a becomes 6.
Total for b: 5+5+5=15.