This is the 10th day of my participation in Gwen Challenge
The assignment operator
The operator | describe | The instance |
---|---|---|
= | Simple assignment operator that assigns the value of the right-hand operand to the left-hand operand | C = A + B will assign the value of A + B to C |
+ = | The add and assign operator assigns the result of adding the right-hand operand to the left-hand operand | C plus A is the same thing as C is equal to C plus A |
– = | The subtract and assignment operator assigns the result of subtracting the right-hand operand from the left-hand operand to the left-hand operand | C minus A is the same thing as C minus A |
* = | Multiply and assign the result of multiplying the right-hand operand by the left-hand operand to the left-hand operand | C times A is the same thing as C times A |
/ = | The division and assignment operator assigns the result of dividing the left operand by the right operand to the left | C over A is the same thing as C is equal to C over A |
% = | Modulo and assignment operator, find the modulo of the two operands and assign to the left-hand operand | C %= A is the same thing as C = C % A |
< < = | Left shift and assignment operator | C <<= 2 is the same as C = C << 2 |
& = | The bitwise and and assignment operator | C&2 is the same thing as c&2 |
> > = | Shift right and assign operator | C >>= 2 is the same as C = C >> 2 |
^ = | Bitwise xOR and assignment operator | C to the 2 is the same thing as C to the 2 |
| = | Bitwise or and assignment operator | C C = C | of the | = 2 is equal to 2 |
Miscellaneous operators
The operator | describe |
---|---|
sizeof | The sizeof operatorReturns the size of a variable. For example, sizeof(a) will return 4, where a is an integer. |
Condition ? X : Y | Conditional operator. If Condition is true, right? Then the value is X: otherwise the value is Y. |
. | Comma operatorIt performs a sequence of operations in sequence. The value of the entire comma expression is the value of the last expression in the comma-separated list. |
. (dot) and -> (arrow) | Member operatorMembers used to refer to classes, structures, and bodies. |
Cast | Cast operatorTo convert one data type to another. For example, int(2.2000) will return 2. |
& | The pointer operator &Returns the address of the variable. For example, & a; The actual address of the variable is given. |
* | The pointer operator *Point to a variable. For example, * var. Will point to the variable var. |
Sign priority
The precedence of the operator determines the combination of items in the expression. This affects how an expression is evaluated. Some operators have higher precedence than others; for example, multiplication and division operators have higher precedence than addition and subtraction operators. For example, x = 7 + 3*2. Here, x is assigned 13, not 20, because the operator * has a higher priority than +, so multiply 3*2 first, then add 7. The following table lists the operators in order of priority, with operators with higher priority appearing at the top and operators with lower priority appearing at the bottom. In an expression, the higher-priority operator is evaluated first.Copy the code
category | The operator | associativity |
---|---|---|
The suffix | () [] ->. ++ – | From left to right |
, | * / % | From left to right |
Add and subtract | + – | From left to right |
shift | << >> | From left to right |
equal | = =! = | From left to right |
With the AND | & | From left to right |
An exclusive or XOR | ^ | From left to right |
OR the OR | | | From left to right |
Logic AND the AND | && | From left to right |
Logic OR the OR | || | From left to right |
conditions | ? : | From right to left |
The assignment | = + = = * = / = % = > > < < = = & = ^ = | = | From right to left |
The comma | . | From left to right |