Both of your cases are undefined, as the C standard does specifically says [something like] "no variable must be updated twice within the same sequence point". Since a sequence point is roughly the same as a statement [there are places where it isn't, but we'll ignore that for now], yourbreaks that rule.Code:k = i++ - i++;
What actually happens is that the compiler will order the increement of i and subtract independently of each other, which means that it may do:
orCode:k = i - i; i++; i++;
And likewise for the ++i variant.Code:i++; k = i (i++;) - i; // Not C syntax! It does i++ after taking the first value of i.
Finally, in theory, the compiler is perfectly allowed to come up with ANY numeric answer - the fact that you are getting some sort of reasonable answer is entirely based on the compiler doing "something sensible", but it's not guaranteed to do that.
--
Mats