i=i++ is undefined.
Read more here: http://c-faq.com/~scs/readings/undef.950321.html
Edit: The answer to "why or why not?" is a long, unpleasant, and unsatisfying one.
i=i++ is undefined.
Read more here: http://c-faq.com/~scs/readings/undef.950321.html
Edit: The answer to "why or why not?" is a long, unpleasant, and unsatisfying one.
The expression i = i++ gives undefined behaviour because you cannot assign to the same variable twice unless there is a sequence point between the assignments.
An often-cited example is the expression
i=i++, which both assigns i to itself and increments i. The final value of i is ambiguous, because, depending on the language semantics, the increment may occur before or after the assignment. The definition of a particular language might specify one of the possible behaviors or simply say the behavior is undefined. In C and C++, evaluating such an expression yields undefined behavior.