Mask-group

Operators in C



Priority of Operators:

Priority

Operators

Description

1st

* / %

multiplication. division. modular division

2nd

+ -

addition, subtraction

3rd

=

assignment

Associativity of Operators:

Operator

Description

Associativity

( )

Parentheses or function call

left to right

[ ]

Brackets or array subscript

left to right

.

Dot or Member selection operator

left to right

- >

Arrow operator

left to right

+ + - -

Postfix increment/decrement

left to right

+ + - -

Prefix increment/decrement

right to left

+ -

Unary plus and minus

right to left

! ~

not operator and bitwise complement

right to left

(type)

type cast

right to left

*

Indirecton or dereference operator

right to left

&

Address of operator

right to left

sizeof

Determine size in bytes

right to left

* / %

Multiplication, division and modulus

left to right

+ -

Addition and Subtraction

left to right

<<  >>

Bitwise left shift and right shift

left to right

<  <=

relational less than/less than equal to

left to right

>  >=

relational greater than/greater than equal or equal to

left to right

==  !=

Relation equal to or not equal to

left to right

&&

Bitwise AND

left to right

^

Bitwise exclusive OR

left to right

|

Bitwise inclusive

left to right

&&

Logical AND

left to right

| |

Logical OR

left to right

? :

Ternary operator

right to left

=

Assignment operator

right to left

+=   -=

Addition/ Subtraction assignment

right to left

*=   /=

Multiplication/ division assignment

right to left

%=   &=

Modulus and Bitwise assignment

right to left

^= |=

Bitwise exclusive/inclusive OR assignment

right to left

<<=   >>=

 

right to left

,

comma operator

left to right

  • When an expression contains two operators of equal priority then it is settled using associativity of operators.

  • It is of two types:
    Left to Right or Right to Left.

  • The above table shows the associativity of various operators.