C Operator priority, operator priority
Priority |
Operator |
Name or meaning |
Usage |
Integration direction |
Description |
1 |
[] |
Array subscript |
Array name [constant expression] |
Left to right |
|
() |
Parentheses |
(Expression)/function name (parameter table) |
|
. |
Member selection (object) |
Object. member name |
|
-> |
Member selection (pointer) |
Object Pointer-> member name |
|
2 |
- |
Negative Operator |
-Expression |
Right to left |
Single Object Operator |
(Type) |
Forced type conversion |
(Data Type) Expression |
|
++ |
Auto-increment operator |
++ Variable name/variable name ++ |
Single Object Operator |
-- |
Auto-subtraction Operator |
-- Variable name/variable name -- |
Single Object Operator |
* |
Value Operator |
* Pointer variable |
Single Object Operator |
& |
Bitwise operators |
& Variable name |
Single Object Operator |
! |
Logical non-Operator |
! Expression |
Single Object Operator |
~ |
Bitwise Inverse Operator |
~ Expression |
Single Object Operator |
Sizeof |
Length Operator |
Sizeof (expression) |
|
3 |
/ |
Division |
Expressions/Expressions |
Left to right |
Binary Operators |
* |
Multiplication |
Expression * Expression |
Binary Operators |
% |
Remainder (Modulo) |
Integer expression/Integer expression |
Binary Operators |
4 |
+ |
Add |
Expression + expression |
Left to right |
Binary Operators |
- |
Subtraction |
Expression-expression |
Binary Operators |
5 |
< |
Move left |
Variable <expression |
Left to right |
Binary Operators |
> |
Right Shift |
Variable> Expression |
Binary Operators |
6 |
> |
Greater |
Expression> Expression |
Left to right |
Binary Operators |
> = |
Greater than or equal |
Expression> = expression |
Binary Operators |
< |
Less |
Expression <expression |
Binary Operators |
<= |
Less than or equal |
Expression <= expression |
Binary Operators |
7 |
= |
Equal |
Expression = expression |
Left to right |
Binary Operators |
! = |
Not equal |
Expression! = Expression |
Binary Operators |
8 |
& |
Bitwise AND |
Expressions & Expressions |
Left to right |
Binary Operators |
9 |
^ |
Bitwise OR |
Expression ^ expression |
Left to right |
Binary Operators |
10 |
| |
By bit or |
Expression | expression |
Left to right |
Binary Operators |
11 |
&& |
Logic and |
Expressions & Expressions |
Left to right |
Binary Operators |
12 |
| |
Logic or |
Expression | expression |
Left to right |
Binary Operators |
13 |
? : |
Conditional Operators |
Expression 1? Expression 2: expression 3 |
Right to left |
Three-object Operator |
14 |
= |
Value assignment operator |
Variable = expression |
Right to left |
|
/= |
Assignment After Division |
Variable/= expression |
|
* = |
Assign value after Multiplication |
Variable * = expression |
|
% = |
Assign value after modulo operation |
Variable % = expression |
|
+ = |
Add and assign values |
Variable + = expression |
|
-= |
Value after subtraction |
Variable-= expression |
|
<= |
Value after left shift |
Variable <= expression |
|
>>= |
Value after right shift |
Variable> = expression |
|
& = |
Bitwise AND postvalue |
Variable & = expression |
|
^ = |
Value Based on bitwise XOR |
Variable ^ = expression |
|
| = |
Value by bit or after |
Variable | = expression |
|
15 |
, |
Comma Operator |
Expressions, expressions ,... |
Left to right |
Sequential operation from left to right |
Note:
For operators with the same priority, the operation order is determined by the combination direction.
! > Arithmetic Operators> Relational operators >&>||> value assignment operators
Among all priorities, only three are combined from right to left. They are single object operators, condition operators, and value assignment operators. All others are from left to right.
Note that ++ and -- are right combinations. Therefore, the combination of ++ a ++ is equivalent to ++ (a ++). Of course, a ++ is a left value, so this expression is incorrect.
In C, only four operators specify the operation direction. They are &, |, conditional operators, and value assignment operators.
&, | The value of the Left expression is calculated first. When the value of the Left expression can determine the value of the entire expression, the value of the right expression is no longer calculated. For example, if a = 0 & B; & the left digit of the operator is 0, expression B on the right is no longer judged.
In the conditional operators. Such as? B: c; first judge the value of a, and then evaluate one of B or c based on the value of.
The value assignment expression requires that the expression on the right be evaluated first, so that a = B = c = 6; is possible.