In C ++, there are many operators. Here we will list some of them to illustrate the most commonly used operators, which are listed below ,. These contents are found on some portals and technical forums. I have not picked out many errors in the middle. please correct me.
Examples of common C ++ operator operators:
- Arithmetic Operators
-
- + AddX=Y+ Z;
-
- -SubtractionX=Y-Z;
-
- * MultiplicationX=Y* Z;
-
- /DivisionX=Y/Z;
-
- Value assignment operator
-
- = Value assignmentX=10;
-
- + = Value assignment and x + = 10; (equalXX= X + 10 ;)
-
- -= Value assignment and SubtractionX-=10;
-
- * = Value assignment and multiplication x * = 10;
-
- \ = Assignment and Division x \ = 10;
-
- & = Value assignment and x & = 0x02;
-
- | = Assign a value or x | = 0x02;
-
- Logical operators
-
- & Logic and if (x & 0xFF ){...}
-
- | Logic or if (x | 0xFF ){...}
-
- Equality Operators
-
- = Equal to if (X= 10 ){...}
-
- ! = Not equal to if (x! = 10 ){...}
-
- <Less than if (x< 10){...}
-
- >Greater than if (x>10 ){...}
-
- <= Less than or equal to if (x<= 10 ){...}
-
- >= Greater than or equal to if (x>= 10 ){...}
-
- Unary operator
-
- * Indirect operator intX= * Y;
-
- & Address operator int *X= & Y;
-
- ~ Non-x ~ 0x02;
-
- ! The logic is not if (! Valid ){...}
-
- ++ Increment operator x ++ equalsXX= X + 1 ;)
-
- -- Decrease operator x --;
-
- Class and structure Operators
-
- : Scope resolution MyClass: SomeFunction ();
-
- ->Indirect member MyClass->SomeFunction ();
-
- · Directly member MyClass. SomeFunction ();
It can be seen that this list is longer and cannot be remembered at once. When using the C ++ operators, you will gradually become familiar with these operators. It must be noted that the incrementing operator can be either a forward incrementing (++ x) or a post-incrementing (x ++ ). The increment operator tells the compiler to increment first and then use the variable. Then, the increment operator allows the compiler to increment first with the variable value. For example, the following code:
- IntX=10;
-
- Cout<<"X="<< X++<< End1;
-
- Cout<<"X="<< X << End1;
-
- Cout<<"X= "X<< End1;
-
- Cout<<"X="<<++ X<< End1;
-
- The output result is as follows:
-
- X=10
-
- X=11
-
- X=12
-
- X=12
This is also the case with the drop-down operator. I don't want to talk too much about this content here, but the reader can read it patiently, as Peng Zi told Augusta, "OGU, be patient, rome was not built in one day ". It indicates that operators in C ++ can be overloaded ).
Programmers can use standard overload operators to perform specific operations in specific classes. For example, you can use the overload increment operator in a class to increase the variable by 10 instead of by 1. Operator overload is an advanced C ++ technology, which is not described in detail in this book.
You may find that some operators use the same symbol. The meaning of a symbol varies with the situation. For example, an asterisk (*) can be used as a multiplication number, a pointer is declared, or a pointer reference is canceled. This seems a bit messy at the beginning. In fact, the C ++ operator is sometimes confused. More practices, you will gradually adapt. There are many examples in this book to introduce these operators. Readers do not have to memorize the role of each operator, but can understand its role through programs and code segments in learning.