You're (partially) correct. The precedence of the assignment operator is indeed lower than the postfix operator. However, where you're incorrect is what the postfix operator means.
According to the C11 Specification, Sec. 6.5.2.4:
The result of the postfix ++ operator is the value of the operand. As a side effect, the value of the operand object is incremented (that is, the value 1 of the appropriate type is added to it). See the discussions of additive operators and compound assignment for information on constraints, types, and conversions and the effects of operations on pointers. The value computation of the result is sequenced before the side effect of updating the stored value of the operand.
The specification is very clear about the semantics of this operator. It resolves to the original value of the operand and as a later side-effect its value is increased.
If you're looking to increment the value of both a
and b
in your example, use the prefix operator which is guaranteed to increment the value before the assignment.
However, remember, using both postfix and prefix operators on the same variable in a single expression is undefined behavior. Don't do that!