Can anyone pls explain the output for this

int main()
{
int i=10;
printf("%d %d %d",i++,--i,i);
return 0;

according to me the o/p should be 9 9 10 however gcc compiler is giving o/p is 9 10 10

can anyone explain me this....

Refer to this similar thread
http://www.daniweb.com/software-development/c/threads/405549

i checked the post.
but i am not able to get it..

when i execute the code on turbo c++ i get what i expect, but i am getting some other answer on gcc compiler.. why is that?

int main()
{
int i=5;
printf("%d %d %d",i,i++,++i);
return 0;
}

turbo C compiler outputs 7 6 6
where as gcc is giving 7 6 7


please explain... i m losing my head :sweat:

The result is undefined. Hence different for different compilers. That is what is given in the previous post.

It is not guaranteed that an increment or decrement is performed immediately after giving up the previous value and before any other part of the expression is evaluated. It is merely guaranteed that the update will be performed sometime before the expression is considered "finished".

So, using of increments or decrements 1 at a time gives accurate result. But if used collectively, the compiler itself choses the increment or decrement to be performed and gives you a messy result. :P

I think it would help you...i posted same reply in that post also.. :D

This article has been dead for over six months. Start a new discussion instead.