Operator Precedence : Associativity and Priority




C Programming Operator Precedence and Associativity
C Programming supports wide range of Operators . While Solving the Expression we must follow some rules , Example : while Solving the expression [ a + b *c ] , we should first perform Multiplication Operation and then Addition . Similarly in order to solve such complicated expression you should have hands on Operator Precedence and Associativity of Operators. Precedence of the Operator are Listed in the Following Table and This Table is Summarized in decreasing Order of Priority i.e Topmost Operator has Highest Priority and Bottommost Operator has Lowest Priority.


    Description                     Operator                    Associativity
Increment
Decrement
Negation
Unary Minus
Sizeof
++
-
!
-
sizeof
R -> L
Multiplication
Division
Modulus
*
/
%
L -> R
Addition
Subtraction
+
-
L -> R
Shift Operator

<<
>>
L -> R
Less Than
Greater Than
Less Than and Equal to
Greater Than and Equal to
<
>
<=
>=
L -> R
Equal to
Not Equal To
==
!=
L -> R
Logical AND&&L -> R
Logical OR||L -> R
Conditional?:R -> L
Assignment=
+=
-=
*=
/=
R -> L
Comma,L -> R

Notes :

  1. Comma Operator Has Lowest Precedence .
  2. Unary Operators are Operators having Highest Precedence.
  3. Sizeof is Operator not Function .
  4. Operators sharing Common Block in the Above Table have Equal Priority or Precedence .
  5. While Solving Expression , Equal Priority Operators are handled on the basis of FIFO [ First in First Out ] i.e Operator Coming First is handled First.

Some Definitions :

Unary Operator  :
  • A unary operation is an operation with only one operand, i.e. an operation with a single input .
  • A unary operator is one which has only one operand. e.g.
    post / pre increment operator.

Binary Operator
  • A Binary operator is one which has two operand. e.g.
    plus , Minus .

Important Terms :

Associativity
  • Their associativity indicates in what order operators of equal precedence in an expression are applied
Precedence
  • Priority Of Operator