James said:
No it doesn't. As Pete has already said, it's irrelevant here,
since the code has undefined behavior, but all the standard says
is that the variable will be incremented before the next
sequence point. Even if there wasn't undefined behavior.
But (as far as I know) jumping to a function call (in this case
printf) marks a sequence point, so the variable must have been
incremented before the code jumps to the printf function.
I think it's thus pretty unambiguous that the variable a will have
been incremented twice before the printf call is executed, and thus will
have a value of 7. It's also pretty unambiguous that the value 5 cannot
be part of the multiplication because the very definition of the
prefix++ operator makes that impossible. The only thing which in
practice is not guaranteed in "++a*++a" is in which order the variable a
is incremented and its value used in with the binary operator*.
Thus, in practice, only four things can conceivably happen:
1) The first "++a" is executed first, incrementing the value of a, and
the value of that expression will be 6. After this the second "++a" is
executed and this results in 7 as the second operand, and thus the
result will be 42.
2) The reverse happens: The second "++a" is executed first, its value
taken, and then the first one. The result of the multiplication will
still be the same.
3) Both "++a" operators are executed first, after which the value of a
(ie. 7) is used as the parameters of the multiplication, which results
in 49.
4) The compiler decides that the value of the expression "++a" is 6, and
thus uses 6 as the value for both operands of the operator*. Thus the
result of the multiplication will be 36. (Although I would say that this
case is the most unlikely of the four in practice.)
I see no logical reason why any compiler would produce anything else
than something that prints 36, 42 or 49.
But of course this is just theoretizing about compiler behavior in
practice. It's not like you should ever use anything like "++a*++a".