C language auto-incrementing ++-detailed explanation

Source: Internet
Author: User

C language auto-incrementing operator Summary
[Example]
Int I = 5, j = 5, p, q;
P = (I ++) + (I ++ );
Q = (++ j) + (++ j );
Printf ("% d, % d \ n", I, j, p, q );
I = 5;
J = 5;
P = (I ++) + (I ++ );
Q = (++ j) + (++ j );
Printf ("% d, % d \ n", I, j, p, q );
I = 5;
J = 5;
P = (I ++) + (I ++ );
Q = (++ j) + (++ j );
Printf ("% d, % d \ n", I, j, p, q );
I = 5;
J = 5;
P = (I ++) + (I ++ );
Q = (++ j) + (++ j );
Printf ("% d, % d \ n", I, j, p, q );
[Description]
Compile and run in VC6.0.
The running result of this program is
7, 7, 10, 14
8, 8, 15, 22
9, 9, 15, 22
10, 10, 25, 41
It can be seen that after the complete subcomputation OF a ++, several ++ operations are counted, and then a few more are added to. While
++ A: When there are less than two operations, calculate the number of ++ operations first, then add them, and then assign values. If there are more than two, the third start is step-by-step. The first two are completed, and the third end uses the obtained value. Therefore, q = (++ j) + (++ j); (j = 5) q is equal to 7 + 7 + 8 = 22.
To sum up, in the vc environment: ++ I first increases the value of I twice and then assigns a value! I ++ first assigns a value and then increases the value of I twice!
Note]
The object of the auto-incrementing auto-subtraction operator is a variable, not a constant or expression. For example, ++ I ++ j is invalid. This is because the C-language compiler makes up as many characters as possible as an operator or identifier during program compilation from left to right, therefore, ++ I ++ j is equivalent to ++ (I ++) + j, the 1st "++" objects are used to define the expression "I ++", which is not allowed.

Author "record bit by bit"

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.