The next + + operation in development is a puzzle

Source: Internet
Author: User

Post + + operations, tested in JavaScript and Java

var k = 0;

K = k++;

Console.log (k); 0

//////////////////////////////////////////////////////////////////

int i = 0;

i = i++;

System.out.println (i);//0

Why the result is 0 instead of 1, the computer performs the second + + at the time of calculation,

If you need the result is 0, then need to use the front + +, this does not have to say, do not understand the test under their own

So let's look at one more case:

var k = 0;

k++;

Console.log (k);

What is the result of this? That's right, 1, don't get confused by the case above.

Why would that be?

The process of execution is top-down, then the second equals 1, which can understand

The first one is because the Post + + is executed later than the assignment, and when the discovery needs to be performed,

will be assigned to call first, after the execution of the + + operation, so you understand it

The next + + operation in development is a puzzle

Related Article

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.