Prefix increment and decrement operators: + + and-Grammar
+ + Unary-expression––unary-expression
NoteThe prefix increment operator (+ +) adds 1 to its operand, which is the result of an expression. The operand must be a left value that is not a
1. Increment decrement operatorThe C + + language does not require that the increment decrement operator be a member of a class. But because they change exactly the state of the object being manipulated. Therefore, it is recommended to set the
The self-increment "+ +" and "subtract"--"are unary operators, and both the pre-and post-form can be overloaded. Take a look at the following example:#include #includeusing namespacestd;classstopwatch{//StopwatchPrivate: intMin//minutes intSec/
Transferred from: http://bbs.csdn.net/topics/330189207C language's self-increment + +, self-subtraction-operator has always been a problem for beginners, and even a lot of veteran will be confused, recently I saw a problem on the Internet:#include
Increment decrement operator
Before increment ++++ $a $ A increments by 1 and then returns $ A
After increment + + + $a first return $ A, then $ A since 1
Before decrement----$a $ A self minus 1 and then return $ A
After decrement--$a--returns $ A,
The self-increment operator "+ +" and the decrement operator "--" contain two versions respectively. That is, operator pre-form (such as ++x) and operator post-form (such as x + +), the two operations are not the same. Therefore, when we overload
Increment operator + +, increase the value by 1, the decrement operator---to reduce the value by 1
Operator
Code Snippets
Difference
++
x = 2 * m + +;
First Run x = 2 * m; Re-run m = m + 1;
In JavaScript, incrementing decrements belong to the unary operator, the so-called unary operator, which is an operator that can manipulate only one value.Increment and decrement operators are available in two versions: pre-and post-built. As the
1. Increment/decrement operator equivalencea=b++;
a=b;b=b+1;A=++b; b=b+1;b=b;a=b--; a=b;b=b-1;A=--b; b=b-1;b=b;So, a=5;b=6;var3=a++*--b, the result is 25.2. Assignment operator equivalent with operationA*=b; a=a*b;A/=b; a=a/b;A+=b;
Look at the operator overloads of C #, and find that they are not the same as C + +. Just been in the C # self-increment operator pit, now to share.First define a class class A { publicint i; Public A (int i) {
1. Since the pre-increment and post-increment operators are unary operators, the overloads are distinguished by adding an int parameter (dummy parameter) to the post-increment, and when the post-increment is called, the compiler automatically
Preliminary C + + operator overloading Learning notes Preliminary Discussion on C + + operator overloading Learning notes overloading as friend functionsIncrement, decrement operator + + (--) has two forms: former self-increment ++i
In addition to this +-*/% of these 5 arithmetic operators there are actually 2 + +-These two can also belong to the arithmetic operator. He is the self-increment of the decrement operation, for example: int i = 10; i++; I--or ++i-I but these 2 are
Absrtact: In C language teaching, the self-increment self-subtraction operator is widely used, and it has certain skill and difficulty. Among the many operators, the self-increment decrement operator is the most difficult to understand and the most
This chapter describes the PHP operators.
Operator this is a problem in every language, because we are already familiar with one or more of the programming languages, so we just need to know.
Summarize it.
There are many kinds of PHP operators,
Java provides rich operators, such as arithmetic operators, relational operators, logical operators, bitwise operators, and so on. an expression in Java is a Java-compliant formula that is concatenated with operators . The precedence of an operator
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.