Operator Precedence and Associativity in C
Each operator in C has a precedence associated
with it. The precedence of operators determines the order in which they are
evaluated in an expression. Operators with higher precedence are evaluated
first.
|
Operator
|
Description |
Associativity |
Precedence
|
|
( ) |
Function call |
Left-to-Right |
1 |
|
[ ] |
Array element reference |
||
|
|
|||
|
+ |
Unary plus |
Right-to-Left |
2 |
|
- |
Unary minus |
||
|
++ |
Increment |
||
|
-- |
Decrement |
||
|
! |
Logical negation |
||
|
~ |
Ones complement |
||
|
* |
Pointer reference (indirection) |
||
|
& |
Address |
||
|
sizeof |
Size of an object |
||
|
(type) |
Type cast(conversion) |
||
|
|
|||
|
* |
Multiplication |
Left-to-Right |
3 |
|
/ |
Division |
||
|
% |
Modulus |
||
|
|
|||
|
+ |
Addition |
Left-to-Right |
4 |
|
- |
Subtraction |
||
|
|
|||
|
<< |
Left Shift |
Left-to-Right |
5 |
|
>> |
Right shift |
||
|
|
|||
|
< |
Less than |
Left-to-Right |
6 |
|
<= |
Less than or equal to |
||
|
? |
Greater than |
||
|
>= |
greater than or equal to |
||
|
|
|||
|
== |
Equality |
Left-to-Right |
7 |
|
!= |
Inequality |
||
|
|
|||
|
& |
Bitwise AND |
Left-to-Right |
8 |
|
|
|||
|
^ |
Bitwise XOR |
Left-to-Right |
9 |
|
|
|||
|
| |
Bitwise OR |
Left-to-Right |
10 |
|
|
|||
|
&& |
Logical AND |
Left-to-Right |
11 |
|
|
|||
|
|| |
Logical OR |
Left-to-Right |
12 |
|
|
|||
|
?: |
Conditional expression |
Right-to-Left |
13 |
|
|
|||
|
= |
Assignments operators |
Right-to-Left |
14 |
|
*= /=
%= |
|||
|
+= -= &= |
|||
|
^= |= |
|||
|
<<= ??=\ |
|||
|
|
|||
|
, |
Comma operator |
Left-to-Right |
15 |
No comments:
Post a Comment