Difference between i = ++i and ++i [duplicate]-Collection of common programming errors
Writing i = ++i;
writes to variable i
twice (one for the increment, one for the assignment) without a sequence point between the two. This, according to the C language standard causes undefined behavior.
This means the compiler is free to implement i = ++i
as identical to i = i + 1
, as i = i + 2
(this actually makes sense in certain pipeline- and cache-related circumstances), or as format C:\
(silly, but technically allowed by the standard).
Originally posted 2013-11-09 23:22:50.