Operator precedence and operator associativity rules in c++ [duplicate]

Standard says: “Between the previous and next sequence point a scalar object shall have its stored value modified at most once by the evaluation of an expression” (5 Expressions, §4), i.e. the following:

a += a +  ++a 

yields undefined behavior just like:

a = ++a;

does already. It also says: “the prior value shall be accessed only to determine the value to be stored”, i.e. if you want to change a, you can use a in the same expression just to retrieve the previous value:

a = a + 1; // OK

“otherwise the behavior is undefined.”

Leave a Comment