1

Possible Duplicate:
Could anyone explain these undefined behaviors (i = i++ + ++i , i = i++, etc…)

I have an expression in a program, initial value of i = 10

int j = i++ + i++;

it sets j as 20 but

int j = i++ + ++i;

it sets j as 22
Why is there a difference of two between statements? I think, difference should be of 1.
I know this is undefined in C, but why GCC is doing such things?

4

1 回答 1

-1

对于 i++,它就像:首先做方程,然后增加 i。

对于 ++ i 就像:首先增加 i 然后做方程。

所以我猜 i++ + ++i 被解释为 i + (++(++i)) 所以结果是 22。

有线的事情发生在有线的语法上,只是不要做这样的事情;)。

如果我是对的 ++i + ++i 也将是 22。

于 2012-10-28T20:12:34.120 回答