Possible Duplicate:
Could anyone explain these undefined behaviors (i = i++ + ++i , i = i++, etc…)
I have encountered with a strange problem regards increment operator.
I get different output of same expression in PHP and C.
In C language
main()
{
int i = 5;
printf("%d", i++*i++); // output 25;
}
In PHP
$i = 5;
echo $i++*$i++; // output 30
Can anyone explain this strange behavior? Thanks.
In C the result is undefined because either of the two operands could be evaluated first, thus reading it a second time is erroneous.
And, well, in PHP I wouldn’t be surprised if the result was 42 pending some changes to php.ini.