Operations and operators in C language and operators in C Language
1. Operator priority and associativity 1. Priority
In the operator list, the higher the operator, the higher the priority.
2. associativity
If O is used to represent binary operators that require two operands, then the expression aObOc:
The left Union operator interprets the expression as (aOb) Oc [left Union]
The right Union operator interprets the expression as aO (bOc) [right Union]
Conclusion: When an operator with the same priority is encountered, the combination indicates whether the expression should be operated from left to right or from right to left.
Ii. Operator list
Priority |
Operator |
Form |
Name |
Associativity |
1 |
() |
X (y) |
Function call Operators |
Left |
1 |
[] |
X [y] |
Subscript operator |
Left |
1 |
. |
X. y |
. Operator (period operator) |
Left |
1 |
-> |
X-> y |
-> Operator (arrow operator) |
Left |
1 |
++ |
X ++ |
Post-incrementing Operator |
Left |
1 |
-- |
Y -- |
Post-decimal Operator |
Left |
2 |
++ |
++ X |
Increment operator |
Right |
2 |
-- |
-- Y |
Decimal front Operator |
Right |
2 |
Sizeof |
Sizeof x |
Sizeof Operator |
Right |
2 |
& |
& X |
Single Object operator & (addressing operator) |
Right |
2 |
* |
* X |
Single Object operator * (pointer operator) |
Right |
2 |
+ |
+ X |
Single Object operator + |
Right |
2 |
- |
-X |
Single Object operator- |
Right |
2 |
~ |
~ X |
~ Operator (bitwise complement operator) |
Right |
3 |
! |
! X |
Logical non-Operator |
Right |
3 |
() |
(X) y |
Type conversion Operator |
Right |
4 |
* |
X * y |
Binary operator * |
Left |
4 |
/ |
X/y |
/Operator |
Left |
4 |
% |
X % y |
% Operator |
Left |
5 |
+ |
X + y |
Binary operators + |
Left |
5 |
- |
X-y |
Binary operators- |
Left |
6 |
< |
X <y |
<Operator |
Left |
6 |
> |
X> y |
> Operators |
Left |
7 |
< |
X <y |
<Operator |
Left |
7 |
<= |
X <= y |
<= Operator |
Left |
7 |
> |
X> y |
> Operators |
Left |
7 |
> = |
X> = y |
> = Operator |
Left |
8 |
= |
X = y |
= Operator |
Left |
8 |
! = |
X! = Y |
! = Operator |
Left |
9 |
& |
X & y |
Bitwise AND operator |
Left |
10 |
^ |
X ^ y |
Bitwise OR operator |
Left |
11 |
| |
X | y |
Bitwise OR operator |
Left |
12 |
&& |
X & y |
Logic and operators |
Left |
13 |
| |
X | y |
Logic or operator |
Left |
14 |
? : |
X? Y: z |
Conditional Operators |
Right |
15 |
= |
X = y |
Basic assignment operator |
Right |
15 |
+ =-= * =/= <=> = & = ^ = | = |
|
Compound assignment operator |
Right |
16 |
, |
X, y |
Comma Operator |
Left |