# Auto-plus ++

Source: Internet
Author: User

I ++ adds 1 after use

++ I add 1 before use

Int A = ++ I;

How is it calculated?

++ I;

++ I;

A = I + I = 2 + 2 = 4;

How is I ++ calculated?

A = I ++;

First execute a = I + I;

Then I ++;

I ++;

Let's look at the following code:

`// Example 1 # include <iostream> # include <cstdlib> using namespace STD; void main () {int C = 0, a = 0, B = 0; cout <"twice using ++ a" <Endl; C = (++ A) + (++ ); cout <"the value of C is" <C <Endl; C = a +; cout <"the value of C is" <C <Endl; cout <"twice using B ++" <Endl; C = (B ++) + (B ++); cout <"the value of C is" <C <Endl; C = B + B; cout <"the value of C is" <C <Endl; a = 0; // re-initialize the combination of variable A cout <"A ++ and ++ a, and a ++ is in front of" <Endl; C = (++) + (A ++); cout <"the value of C is" <C <Endl; C = a +; cout <"the value of C is" <C <Endl; a = 0; // re-initialize the combination of variable A cout <"A ++ and ++ a, and a ++ is later" <Endl; C = (a ++) + (++ A); cout <"the value of C is" <C <Endl; C = a +; cout <"the value of C is" <C <Endl; a = 0; // re-initialize the variable A cout <"A ++ and two ++ a mixed use" <Endl; C = (a ++) + (++ A); cout <"the value of C is" <C <Endl; C = a +; cout <"the value of C is" <C <Endl; a = 0; // re-initialize the variable A cout <"mixed use of two A ++ and one ++ a" <Endl; C = (a ++) + (A ++) + (++ A); cout <"the value of C is" <C <Endl; C = a +; cout <"the value of C is" <C <Endl; System ("pause ");}`

The execution result is as follows:

Related Keywords:

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.