可能重複:
Could anyone explain these undefined behaviors (i = i++ + ++i , i = i++, etc…)遞增運算符在PHP和C語言
我有一個奇怪的問題,遇到的關於增量運算符。
我得到相同的表達不同的輸出在PHP和C
In C language
main()
{
int i = 5;
printf("%d", i++*i++); // output 25;
}
In PHP
$i = 5;
echo $i++*$i++; // output 30
誰能解釋這種奇怪的行爲?謝謝。
在C中它是未定義行爲,所以技術上你可以得到任何輸出。好的閱讀:[未定義行爲和序列點](http://stackoverflow.com/questions/4176328/undefined-behavior-and-sequencepoints ) –
@Ashwini - 爲什麼這很重要?你會如何使用這樣的代碼? –
在PHP中,這也是未定義的。參見[例1](http://php.net/manual/en/language.operators.precedence.php)。 – netcoder