[Advice] Why are the results of the two addition operations of PHP three?

Source: Internet
Author: User
[Advice] Why are the results of the two addition operations of PHP three?
   

In my understanding, the first result should be 2, and the second result should be 3.
Print output:
int 3int 3


Reply to discussion (solution)

According to the php syntax, your understanding is correct.
The actual running result is not like this, so you can think that this is a php bug.
This bug may also be intended because it is the same in C language.

According to the php syntax, your understanding is correct.
The actual running result is not like this, so you can think that this is a php bug.
This bug may also be intended because it is the same in C language.

Thank you! I have read the post you have replied to before posting http://bbs.csdn.net/topics/390571704, but I still do not understand it, so I sent it again. thank you ~~

According to the php syntax, your understanding is correct.
The actual running result is not like this, so you can think that this is a php bug.
This bug may also be intended because it is the same in C language.

It does not seem like this in moderator C:

#include
  
   int main() {    int a = 1;    printf("a=%d\n",a+a++);    a = 1;    printf("a=%d\n",a+a+a++);    return 0;}
  


Output:
a=2a=3

This is C ++. I am talking about C.


According to the php syntax, your understanding is correct.
The actual running result is not like this, so you can think that this is a php bug.
This bug may also be intended because it is the same in C language.

It does not seem like this in moderator C:

#include
  
   int main() {    int a = 1;    printf("a=%d\n",a+a++);    a = 1;    printf("a=%d\n",a+a+a++);    return 0;}
  


Output:
a=2a=3

Strange .. I am not a C ++ either.

How can I find many posts discussing this problem.

Wikipedia:
In computer programming, Undefined behavior refers to computer code with unpredictable behavior. This is a feature of some programming languages. The most famous is in C language. [1] In these languages, in order to simplify the standards and provide some flexibility, the standards specifically stipulate that the results of some operations are undefined, this means that programmers cannot predict what will happen.

How can I find many posts discussing this problem.

Wikipedia:
In computer programming, Undefined behavior refers to computer code with unpredictable behavior. This is a feature of some programming languages. The most famous is in C language. [1] In these languages, in order to simplify the standards and provide some flexibility, the standards specifically stipulate that the results of some operations are undefined, this means that programmers cannot predict what will happen.

I learned a lot again. thank you !!!

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.