开发者

Operator associavity problem with pre and post increment :( [duplicate]

This question already has answers here: Closed 11 years ago.

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!!!!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜