i++ related issues

Source: Internet
Author: User
I++ 's Problem
int I = 3;
i = i + i++ + ++i;
The above code in the Java/c#/javascript output 11, but in PHP but output 12,php calculation and for his three kinds of what is the difference? Think of the solution, seeking guidance!


------Solution--------------------

$i = 3;
$a = $i + $i + + + + + $i;
echo $a; 12
This is a BUG in PHP
It seems that all php5 have this problem (at least the 3 versions I have at hand are like this)
The problem is in the first $i the method of passing the value, such as writing
$i = 3;
$a = ($d = $i) + $i + + + + $i;
echo $a; 11
It's right.
Obviously the first $i pass the reference, because the $i + + in the back is actually involved in the operation of 4 instead of 3.

It's clearer to remove the + + + $i
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.