Operator associavity problem with pre and post increment :( [duplicate]
P开发者_如何学Goossible Duplicate:
Could anyone explain these undefined behaviors (i = i++ + ++i , i = i++, etc…)
#include< stdio.h >
int main()
{
int i = 1;
int x = ++i * ++i * ++i;
printf("%d\n", x);
printf("%d\n\n",i);
return 0;
}
Im getting output of 1!! and 4 in gcc. I use ubuntu linux
The behaviour of your code is undefined since i
is modified more than once between sequence points:
int x = ++i * ++i * ++i;
See the FAQ (I urge you to read the entire section 3).
Undefined Behaviour this is:
int x = ++i * ++i * ++i;
Don't do it!!!!
精彩评论