Vallabha said:
int i=8;
printf("%d\t%d\t%d\t%d\t%d\t%d\n",i,++i,--i,i--,i++,-i--);
printf("%d\n", i);
why the results is:
8 8 7 8 8 -8
7
How to explain?
I guess you want to someone to explain the reason behind this output..
if so, here is some help for you.
cut down the sample to analyze the things:
[snip]
printf calculates the arguments from right to left and prints them
from left to right.. so i-- is computed first, then --i and then i.
printf might be calculating things left to right on your compiler, but
there is no requirement for it to do so
[snip]
All this results are correct, none of the compilers have bugs, because
quite simply the behaviour of the OP's program, and your program, is
undefined by the C++ standard. One can of course provide an explaination
why one particular compiler produces one particular output, but I don't
think it's particularly useful to do so.