This statement int b = (a) + a++;
is supposed to assign the value 8 to variable b
, where a
is initially assigned the value 4. However, the output of the program is 9 instead of the expected 8.
I expect 8 to be output because ()
and ++
(post) have same precedence and so by their associativity rule (a)
should be evaluated first and then a++
, both of which evaluate to 4. Hence we should have 4 + 4
, which equals '8'.
I would like to understand the reasons behind this unexpected result. Why is the output 9 instead of 8? How does the order of evaluation and the behavior of the increment operator contribute to this outcome?