Operators are roughly divided into the following three types:
- Unary operator, processing an operator
- Binary operator, processing two operands
- Three-element operator, processing three operands
Most operators are binary operators. There are only a few unary operators and a ternary operator, that is, a conditional operator (a conditional operator is a logical operator ). The following describes mathematical operators, including unary and binary operators.
I. mathematical operators
There are five simple mathematical operators, two of which have two forms: two yuan and one yuan. The following table lists these operators and uses a short example to describe their usage and their results when using a simple numeric type.
| Operator |
Class |
Example expression |
Result |
| + |
Binary |
Var1 = var2 + var3; |
The value of var1 is the sum of var2 and var3. |
| - |
Binary |
Var1 = var2-var3; |
The value of var1 is the difference between var2 and var3. |
| * |
Binary |
Var1 = var2 * var3; |
The value of var1 is the product of var2 and var3. |
| / |
Binary |
Var1 = var2/var3; |
Var1 is the value obtained by dividing var2 by var3. |
| % |
Binary |
Var1 = var2 % var3; |
Var1 is the remainder of var2 divided by var3. |
| + |
RMB 1 |
Var1 = + var2; |
The value of var1 is equal to the value of var2. |
| - |
RMB 1 |
Var1 =-var2; |
The value of var1 is equal to the value of var2 multiplied by-1. |
The PS: + (mona1) operator is a bit odd because it has no effect on the result. It does not convert the value to positive: If var2 is-1, + var2 is still-1. However, this is a universally recognized operator, so it is also included.