Explore the c language in front ++ and back ++, explore c

Source: Internet
Author: User

Explore the c language in front ++ and back ++, explore c

Wavelet takes you to explore the front ++ and back ++ in the C language. You are welcome to vomit, and you are welcome to add QQ463431476. Welcome! Now let's explore: Let's first check that the first I is assigned 0, And I ++ (after ++) does not output 1. Now I is assigned 0, ++ I, that is, the first ++ outputs 1. I is assigned a value of 0. The first ++ is to add 1 first and then assign a value to 1. The values of the following I are all 1. I is assigned 0, followed by ++, followed by ++, which means that I am assigned a value first. After the value is assigned, I will add 1 after the end of this statement. The first printf outputs the value 0 from which I starts to be assigned. The first printf is followed by a semicolon (;), which indicates the end of the statement. When this statement ends, I will secretly add 1, and the 2nd printf outputs the I value after the previous statement is processed.
I is assigned 0, I ++; this is a statement. Because there is a semicolon. After adding a value, we assign a value first, and then add another value when the statement ends. I ++; the execution result is 0 + 1 = 1. Printf only outputs the I value.
I is assigned 0 first, And I ++ is followed by a semicolon ";", that is, this statement ends, I ++; the result is 0 + 1 = the value of I after 1 is 1.
I is assigned 0, ++ I. The first ++ is to add 1 first, and then assign it to itself. ++ I; the result is 0 + 1 = 1.


I first assigns a value of 0, ++ I; (first ++) means that I first 0 + 1 = 1, and then assigns a value of 1 to myself. I becomes 1 I ++; (After ++) I has been assigned 1. Here I ++; that is, first assign the value 1 of the previous I to myself as 1, however, a semicolon (;) indicates the end of this statement. When the statement ends with I ++;, 1 + 1 = 2 is executed. I is assigned 0, front ++, I will be 1. The I ++ output in printf can only be the value assigned by itself. 1. If you add another printf ("% d", I) below ); the output I is 2.
To sum up, add 1 to the front ++ and assign the value to the front ++. + + Is to assign values by yourself. After the value is assigned, you must wait until the statement ends before adding 1. Tip: prefix + Postfix. This is what I think. It means that the first step of ++ is plus + 1, and then the last plus + + is assigned a value first. In addition, the principle of prefix and suffix is the same.

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.