C operators priority
priority |
Operators |
Name or meaning |
Use the form |
Joining direction |
Explanation |
1 |
[] |
Array subscript |
Array name [constant expression] |
Left to right |
-- |
() |
Parentheses |
(Expression) / function name (parameter list) |
-- |
||
. |
Member selection (objects) |
Object. Member Name |
-- |
||
-> |
Member selection (pointer) |
Object pointer -> member name |
-- |
||
2 |
- |
Operators negative |
-expression |
Right to Left |
Unary operator |
~ |
Bitwise operator |
~ Expression |
|||
++ |
Increment operator |
++ variable names / variable names + |
|||
-- |
Decrement operator |
- variable names / variable names - |
|||
* |
Dereferencing operator |
* Pointer variable |
|||
& |
The address operator |
&variable name |
|||
! |
Logical NOT operator |
!expression |
|||
(Types of) |
Cast |
(Data type) expression |
-- |
||
sizeof |
Operators length |
sizeof (expression) |
-- |
||
3 |
/ |
except |
Expressions / Expression |
Left to right |
Binary operator |
* |
Multiply |
Expression * expression |
|||
% |
The remainder (modulo) |
Integer expression integer expression% |
|||
4 |
+ |
plus |
Expression + expression |
Left to right |
Binary operator |
- |
Less |
Expressions - Expressions |
|||
5 |
<< |
The left |
Variable << expression |
Left to right |
Binary operator |
>> |
Right |
Variable >> expression |
|||
6 |
> |
more than the |
Expressions> Expressions |
Left to right |
Binary operator |
>= |
greater or equal to |
Expression> = expression |
|||
< |
Less than |
Expression <expression |
|||
<= |
Less than or equal |
Expression <= expression |
|||
7 |
== |
equal |
Expression == expression |
Left to right |
Binary operator |
!= |
not equal to |
Expression! = Expression |
|||
8 |
& |
Bitwise AND |
Expression & expression |
Left to right |
Binary operator |
9 |
^ |
Bitwise XOR |
Expression ^ expression |
Left to right |
Binary operator |
10 |
| |
Bitwise or |
Expressions | Expression |
Left to right |
Binary operator |
11 |
&& |
Logic and |
Expression && expression |
Left to right |
Binary operator |
12 |
|| |
Logical or |
Expressions Expressions || |
Left to right |
Binary operator |
13 |
?: |
Conditional operator |
1 expression? Expression 2: Expression 3 |
Right to Left |
Ternary operator |
14 |
= |
Assignment Operators |
Variable = expression |
Right to Left |
-- |
/= |
In addition to the assignment |
Variable / = Expression |
-- |
||
*= |
Take after the assignment |
Variable * = Expression |
-- |
||
%= |
After the assignment modulo |
Variable = expression% |
-- |
||
+= |
After the addition of the assignment |
Variable + = Expression |
-- |
||
-= |
After subtraction assignment |
Variable - = Expression |
-- |
||
<<= |
Left after the assignment |
<< expression variable = |
-- |
||
>>= |
Right after the assignment |
= Expression variable >> |
-- |
||
&= |
Bitwise and after the assignment |
Variable & = Expression |
-- |
||
^= |
After pressing bit XOR assignment |
Variable expression ^ = |
-- |
||
|= |
After pressing position or assignment |
Variable | = expression |
-- |
||
15 |
, |
Comma operator |
Expression, expression, ... |
Left to right |
-- |
Description:
the same priority of operators, the order of operations is determined by the binding direction.
简单记就是:! > 算术运算符 > 关系运算符 > && > || > 赋值运算符
加减法 " + - " 高于 按位左移右移 ” << >> " 高于 按位运算符 " & | ^ "