C language operator priority order is: bracket members first; all single items second; multiplication and division remainder three, addition and subtraction four; shift five, relationship six; equality (and) inequality ranking Seven; bitwise AND, XOR and bitwise OR, "three-thirds of the world" eighty or ninety; logical OR and AND, twelve and eleven; condition is higher than assignment; comma operation level is the lowest.
There are fifteen priorities in total:
Priority |
Operator |
Name or meaning |
Used form |
Combined direction |
Description |
1 |
[] |
Array subscript |
Array name [constant expression] |
Left to right |
|
() |
Parentheses |
## (expression)/function name (parameter list) | |||
. | Member Select(object) | Object.Member name |
|||
##-> | Member selection (pointer) | Object pointer->Member name | |||
##- | Negative operator | -expression | Right to left | Unary operator | |
Forced type conversion | (data type) expression |
|
|||
Increment operator | Variable name/variable name | Single Operator | |||
Decrement operator | --Variable name/Variable name-- |
Unary operator |
|||
* |
Value operator |
*Pointer variable |
Unary operator |
||
& |
Get address operator |
& variable name |
Unary operator |
||
! |
Logical NOT operation Symbol |
!Expression |
Unary operator |
||
~ |
Bitwise negation operator |
~Expression |
Unary operator |
||
sizeof |
length operator |
sizeof(expression) |
|||
##3 | / | ##exceptexpression/expression | left to right | Binary operator | |
Multiply | expression*expression | binary operator | |||
Remainder (modulo) | Integer expression/integer expression | Binary operation Symbol | |||
plus | Expression expression | Left to right | Binary Operator |
||
- |
Minus |
Expression-expression |
Binary operator |
||
5 |
<< | Shift left | Variable< | Left to right | Binary operator |
##>> | Shift right | Variable>>Expression | Binary operator | ||
6 | ##>is greater than |
| Expression>ExpressionLeft to right | Binary Operator |
|
>= |
Greater than or equal to |
expression>=expression |
binary operator |
||
# #< | ##less thanexpression | ||||
less than or equal to | Expression< ;=expression | binary operator | |||
== | equal to | expression==expression | left to right | Binary operator | |
is not equal to | expression!= expression | binary operator | |||
8 | & | ## bitwise and | Expression&expression | Left to right | Binary operator |
9 | ^ | Bitwise XOR | Expression^Expression | Left to right | Binary operator |
10 | | | bitwise OR | expression|expression | Left to right | Binary operator |
##11 | ##&&Logic and | Expression&&expression | Left to right | Binary operator | |
|| | ##Logical or | Expression||Expression | Left to right | Binary operator | ##13 |
?: | Conditional operator | Expression 1 ? Expression 2: Expression 3 | right to left | ternary operator | 14 |
= | Assignment operator | Variable = expression | right to left | ||
/= | Assignment after division | Variable/=Expression | |||
*= | Multiply and assign value | Variable*=expression | |||
%= | Assign a value after taking the modulus | Variable% =Expression | |||
= | Assignment after addition | Variable = expression | |||
-= | Assignment after subtraction | Variable-=Expression | |||
<<= | Assign value after left shift | Variable<<=expression | |||
#>>= | Assign value after right shift | Variable>>=expression | |||
&= | ##Assignment after bitwise ANDVariable&=Expression | ||||
Assignment after bitwise XOR | Variable^=expression | ||||
##Assignment after bitwise OR |
Variable|=Expression |
|
##15 | ||
, |
Comma operator |
Expression, expression,... |
Left to right |
Operations sequentially from left to right |
##Instructions:
For operators with the same priority, the order of operations is determined by the combination direction.
Function:
"三三天下"八九十;
#
The above is the detailed content of What is the operator precedence rule in C language?. For more information, please follow other related articles on the PHP Chinese website!