What is the difference between ++ I and I ++?

Source: Internet
Author: User

What is the difference between ++ I and I ++?
New programmers may ask what is the difference between ++ I and I ++? For the specific differences, please refer to Xiao Bian.

++ Is an auto-increment operator, and ++ I is equivalent to I = I + 1. Out of the simplicity of the language, programmers use ++ I and I ++ for auto-increment operations. The difference between the two lies in the order of order. It can be understood as follows: I ++ completes what others ask him to do before executing I = I + 1, and ++ I is to execute I = I + 1 and then finish what others want him to do. An example is as follows:

Int a, I = 3;

A = I ++ 1;

The result of a is 4. If I ++ is changed to ++ I, the result is 5. If only the ++ operator does not have other operators, the effects of the two are the same, for example, a common loop statement:

I ++;

Another case is that in the output statement printf ("% d", I ++, I), what is the result, which cannot be determined. This is because it is not executed from left to right, but depends on the compiler's choice. The results of a = I ++ I are also uncertain. You only need to remember not to use the same variable name in these two cases.

The above is the specific difference between ++ I and I ++. Remember that ++ I is used first and then assigned a value, while ++ I is used and assigned first.

Source: Network Teaching Base original address: http://www.studynb1.com/clanguage/250.html

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.