C Operators Precedence and Associativity


C Operators Precedence

 

When more than one operator is written together in the statement used in the program, then it is necessary to know Which calculation is being done first and which calculation is being done after and which calculation is being done from right to left, or which calculation is being done from left to right.

To make it clear, a table is given below which explains the priority and associativity of the operators -

 

Operator Associativity Precedence

( )

Function Call

[ ] 

Array element reference

Left to Right  1

+

Unary Plus

-

Unary Minus

++

Increment

--

Decrement

!

Logical Negation

*

Pointer Reference

&

Address

sizeof

Size of an Object

(type)

Typecast (conversion)

Right to Left  2

*

Multiplication

/

Division

%

Modulus

Left to Right  3

+

Addition

-

Subtraction

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

&

Bitwise AND

Left to Right  8

*

Bitwise XOR

Left to Right  9

|

Bitwise XOR

Left to Right  10

&&

Bitwise AND

Left to Right  11

| |

Logical OR

Left to Right  12

? :

Conditional Expression

Right to Left  13

=

* = / =

% = + =

- = & =

* = | =

Assignment Operators

Right to Left  14

,

Comma Operator

 

Left to Right  15