Consistent with the usage in C language, the increment operator (++) and the decrement operator (--) are both unary operators, that is, the use of a variable. Taking ++, which is the auto-increment operator, as an example, it is determined by the position before and after, whether to "add first and then use" or "use first and then add", as shown in the following code:
#include<iostream>usingnamespacestd;intmain(){inta=10;cout<<a++<<endl;//++ is used first and then added, that is, output first and then add 1cout<<a++<<endl; cout<<a<<endl;return0;}
You can understand by looking at this code and comments. The so-called adding first and then using or using first and then adding is different in different code scenarios. The code here is to use cout to output. You can try to read the output of this program. The correct result should be:
101112
The reason is that the first output is to output 10 first, then add 1, and a becomes 11. The second output is the same as the output of 11, then add 1 to become 12, and the third output is 12.
Please understand and then try it on the computer.