I ++ problems in Java

Source: Internet
Author: User

I ++ has always been afraid of being like a wolf, because it has never dared to face the side effects of it. Today I have carefully understood the mechanism as follows.

When running to I ++, the execution sequence is as follows:

1 ~ I was launched and obtained by users.

2 ~ I execution ++.

3 ~ The user starts to use the introduced I value.


The three steps also explain why I = I ++; The I value obtained by such a statement remains unchanged.


Similarly, the execution sequence of ++ I is as follows:

1 ~ I execution ++.

2 ~ I was launched and obtained by users.

3 ~ The user starts to use the introduced I value.

2012-09

The above is an article from a year ago and will be commented on later this year.

Int I = 0;

I = I ++;

I still stick to pragmatism for such a problem, so I tried it with Visual Studio, QT creator, and eclipse and found that the answer to the C ++ compiler is 1, the Java compiler is 0.

This is not a problem in the C ++ specification, that is, different compilers have different implementations.

Let's take a look at the post ++ operator's statement: "post-auto-increment operations", which is not clearly defined afterwards.

Before getting the right operand? Or after obtaining the right operand?

Not explicitly stated.

Of course, for the absolute, the answer to this question is indeed 0 in the universal sense, because I ++ returns the value before the ++ operation.

However, compiler writers may not be absolute.

We recommend that you write programs less dependent on this undefined situation.

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.