×
☰ Menu

Precedence and Associativity

 

In order to solve complicated expressions, we need Operator Precedence and Associativity of Operators.

 

Precedence: means the priority of operators

Associativity: indicates in what order operators of equal precedence in an expression are applied

 

Order

Category

Operator

Operation

Associativity

1

 

 

( ) ,[ ]

 

 

L → R
Left to Right

2

Unary

 

!
~
+
-
++
- -
&
*
Size of

 

Logical negation (NOT)
Bitwise 1’s complement
Unary plus
Unary minus
Pre or post increment
Pre or post decrement
Address
Indirection
Size of operant in bytes

R → L
Right -> Left

 

4

 

Multiplication

 

*
/
%

 

Multiply
Divide
Modulus

 

L → R

 

5

 

Additive

 

+
-

 

Binary Plus
Binary Minus

 

L → R

 

6

 

Shift

 

<<
>>

 

Shift Left
Shift Right

 

L → R

 

7

 

Relational

 

<
<=
>
>=

 

Less than
Less than or equal to
Greater than
Greater than or equal to

 

L → R

 

8

 

Equality

 

==
!=

 

Equal to
Not Equal to

 

L → R

 

9

 

Bitwise AAND

 

&

 

Bitwise AND

 

L → R

 

10

 

Bitwise XOR

 

^

 

Bitwise XOR

 

L → R

 

11

 

Bitwise OR

 

|

 

Bitwise OR

 

L → R

 

12

 

Logical AND

 

&&

 

Logical AND

 

L → R

 

14

 

Conditional

 

? :

 

Ternary Operator

 

R → L

 

15

 

Assignment

 

= ,*=
%= ,/=
+= .-=
&=,^=
<<=,>>=

 

 

R → L