int x = 0;if (x = 0 | | x = = 0) printf ("%dn", x);p rintf ("%dn", X);
- The priority table for reference C is actually if (x = (0 | | x = = 0))
Will printf out two 1.
Operators of the same precedence, the order of operations is determined by the binding direction.
Simple note is:! > Arithmetic operators > Relational operators > && > | | > Assignment Operators
C Operator Precedence Table
This
page lists C operators the order of
precedence (highest to lowest). Their
associativity indicates in what order operators of equal precedence in an expression is applied.
Operator |
Description |
Associativity |
( ) [ ] . - ++ -- |
Parentheses (function call) (see Note 1) Brackets (array subscript) Member selection via object name Member selection via pointer Postfix increment/decrement (see Note 2) |
Left-to-right |
++ -- + - ! ~ (type) * & sizeof |
Prefix increment/decrement Unary Plus/minus Logical Negation/bitwise Complement Cast (convert value to temporary value of type) Dereference Address (of operand) Determine size in bytes on this implementation |
Right-to-left |
* / % |
Multiplication/division/modulus |
Left-to-right |
+ - |
Addition/subtraction |
Left-to-right |
<< >> |
Bitwise shift left, Bitwise shift right |
Left-to-right |
< <= > >= |
Relational less than/less than or equal to Relational greater than/greater than or equal to |
Left-to-right |
== != |
Relational is equal to/is not equal to |
Left-to-right |
& |
Bitwise and |
Left-to-right |
^ |
Bitwise Exclusive OR |
Left-to-right |
| |
Bitwise inclusive OR |
Left-to-right |
&& |
Logical and |
Left-to-right |
| | |
Logical OR |
Left-to-right |
? : |
Ternary conditional |
Right-to-left |
= += -= *= /= %= &= ^= |= <<= >>= |
Assignment Addition/subtraction Assignment Multiplication/division Assignment Modulus/bitwise and Assignment Bitwise exclusive/inclusive OR Assignment Bitwise Shift Left/right Assignment |
Right-to-left |
|
Comma (separate expressions) |
Left-to-right |
-
Note 1:
-
parentheses A Re also used to group sub-expressions to force a different precedence; Such parenthetical expressions can be nested and is evaluated from inner to outer.
-
Note 2:
-
Postfix increment/decrement has high precedence, but The actual increment or decrement of the operand is delayed (to be accomplished sometime before the statement completes E xecution). So in the statement
y = x * z++; the Current value of
z is used to evaluate the expression (
i.e., &nbs P
z++ evaluates to
z ) and
z only incremen Ted after all else was done. see
postinc.c for Another example.
|
The priority order of the]c character of the polygon question