可能重复:
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