Reproduced in: http://www.jb51.net/article/37282.htm
Whenever you want to find which operator priority high, many times always want to find no, really let people angry! Now, finally have a I personally feel very full of, share to everyone, welcome to shoot Bricks!
C-language operator precedence
Priority level |
Operator |
Name or meaning |
Use form |
Combination direction |
Description |
1 |
[] |
Array subscript |
array name [constant expression] |
Left to right |
-- |
() |
Parentheses |
(expression)/function name (formal parameter list) |
-- |
. |
Member selection (object) |
Object. Member name |
-- |
- |
Member selection (pointer) |
Object pointers, member names |
-- |
|
2 |
- |
Minus sign operator |
-expression |
Right to Left |
Monocular operator |
~ |
Bitwise inverse operator |
~ Expression |
++ |
Self-increment operator |
+ + variable name/variable name + + |
-- |
Self-decrement operator |
--Variable name/variable name-- |
* |
Value operator |
* Pointer variable |
& |
Fetch address operator |
& Variable Name |
! |
Logical non-operator |
! An expression |
Type |
Forcing type conversions |
(data type) expression |
-- |
sizeof |
Length operator |
sizeof (expression) |
-- |
|
3 |
/ |
Except |
An expression/expression |
Left to right |
Binocular operator |
* |
By |
Expression-expression * |
% |
Remainder (modulo) |
Integer expression% integer expression |
4 |
+ |
Add |
An expression + an expression |
Left to right |
Binocular operator |
- |
Reducing |
Expression-expression |
5 |
<< |
Move left |
Variables << expressions |
Left to right |
Binocular operator |
>> |
Move right |
Variables >> expressions |
|
6 |
> |
Greater than |
Expressions > expressions |
Left to right |
Binocular operator |
>= |
Greater than or equal |
Expression->= expression |
< |
Less than |
Expressions < expressions |
<= |
Less than or equal |
Expression-<= expression |
7 |
== |
Equals |
Expression-= = Expression |
Left to right |
Binocular operator |
! = |
Not equal to |
Expression! = Expression |
|
8 |
& |
Bitwise-AND |
Expressions & Expressions |
Left to right |
Binocular operator |
9 |
^ |
Bitwise XOR OR |
An expression ^ expression |
Left to right |
Binocular operator |
10 |
| |
Bitwise OR |
Expression-expression |
Left to right |
Binocular operator |
11 |
&& |
Logic and |
Expressions && Expressions |
Left to right |
Binocular operator |
12 |
|| |
Logical OR |
An expression | | An expression |
Left to right |
Binocular operator |
|
13 |
?: |
Conditional operators |
Expression 1? Expression 2: Expression 3 |
Right to Left |
Trinocular operator |
|
14 |
= |
Assignment operators |
variable = expression |
Right to Left |
-- |
/= |
Assign value after addition |
Variable-/= expression |
-- |
*= |
Multiply post-Assign value |
Variable-*= expression |
-- |
%= |
Assign value after modulo |
Variable-%= expression |
-- |
+= |
Add after Assignment |
Variable + = expression |
-- |
-= |
Reduced-value Assignment |
Variable-= expression |
-- |
<<= |
Assign value after left shift |
Variable-<<= expression |
-- |
>>= |
Assign value after right shift |
Variable->>= expression |
-- |
&= |
Bitwise AND post-assigned values |
Variable-&= expression |
-- |
^= |
Bitwise XOR or post-assignment |
Variable-^= expression |
-- |
|= |
Bitwise OR post-assigned value |
Variable-|= expression |
-- |
|
15 |
, |
Comma operator |
expression, expression,... |
Left to right |
-- |
Description
Operators of the same precedence, the order of operations is determined by the binding direction.
Simple Note is:! > Arithmetic operators > Relational operators > && > | | > Assignment Operators
Example:
Combine the following examples to analyze:
EG1:
int k=7; int x=;p rintf ("%d\n", x%= (k%=5)); // the remainder operator in parentheses first obtains the result x%=2; // then calculate the x=x%2; Result is 0
EG2:
int k=7; int x=;p rintf ("%d\n", x%=k-k%5); // operation result is 2
EG3:
int n=, i=4;p rintf ("%d\n", n%=i+1); // operation result is 0 // %= (take remainder assignment operator) priority is lower than +
C-language operator precedence list (Super detailed---reprint plus own exercise)