If more than operators are involved in an expression, C has a predefined rule of priority for the operators. The rule of priority of operators are called precedence.
If more than one operators of the same precedence(priority), is present in an expression, then the order on which they execute is called the associativity.
The details of the precedence and associativity can be shown in the following table.
Operator | Description | Associativity | Rank(precedence) |
---|---|---|---|
() [] | Function call Array Element Reference | Left to Right | 1 |
+ – ++ — ! ~ * & sizeof (type) | Unary plus Unary Minus Increment Decrement Logical Negation One’s complement Pointer reference (indirection) Address Size of an object Type cast (conversion) | Right to Left | 2 |
* / % | Multiplication Division Modulus | Left to Right | 3 |
+ – | Addition (Binary Plus) Substraction (Binary Minus) | Left to Right | 4 |
<< >> | Left shift Right shift | Left to Right | 5 |
< <= > >= | Less than Less than or equal to Greater than Greater than or equal to | Left to Right | 6 |
== != | Equality Inequality | Left to Right | 7 |
& | Bit-wise AND | Left to Right | 8 |
^ | Bit-wise XOR | Left to Right | 9 |
| | Bit-wise OR | Left to Right | 10 |
&& | Logical AND | Left to Right | 11 |
|| | Logical OR | Left to Right | 12 |
?: | Condiitional Operator | Left to Right | 13 |
=, *=, /=, %=, += -=, &=, ^=, |=, >>=, <<= | Assignment Operator | Right to Left | 14 |
, | Comma Operator | Left to Right | 15 |