C - Operator Operator Precedence

Introduction

The precedence of the operators determines the evaluation sequence on expression.

The following table shows the order of precedence for all the operators in C, from highest at the top to lowest at the bottom.

Precedence         Operators          Description                                                               Associativity

   1               ( )                Parenthesized expression                                                  Left to right
                   []                 Array subscript
                   .                  Member selection by object
                   ->                 Member selection by pointer
                   ++ --              Postfix increment and prefix decrement

   2               +  -               Unary + and  -                                                            Right to left
                   ++ --              Prefix increment and prefix decrement
                   !  ~               Logical NOT and bitwise complement
                   *                  Dereference (also called indirection operator)
                   &                  Address-of
                   sizeof             Size of expression or type
                   (type)             Explicit cast to type such as  (int) or  (double)

   3               *  /  %            Multiplication and division and modulus (remainder)                       Left to right

   4               +  -               Addition and subtraction                                                  Left to right

   5               <<  >>             Bitwise shift left and bitwise shift right                                Left to right

   6               <  <=              Less than and less than or equal to                                       Left to right
                   >  >=              Greater than and greater than or equal to

   7               ==  !=             Equal to and not equal to                                                 Left to right

   8               &                  Bitwise AND                                                               Left to right

   9               ^                  Bitwise exclusive OR                                                      Left to right

 10                |                  Bitwise OR                                                                Left to right

 11                &&                 Logical AND                                                               Left to right

 12                ||                 Logical OR                                                                Left to right

 13                ?:                 Conditional operator                                                      Right to left

 14                =                  Assignment                                                                Right to left
                   +=  -=             Addition assignment and subtraction assignment
                   /=  *=             Division assignment and multiplication assignment
                   %=                 Modulus assignment
                   <<=  >>=           Bitwise shift left assignment and bitwise shift right assignment
                   &=  |=             Bitwise AND assignment and bitwise OR assignment
                   ^=                 Bitwise exclusive OR assignment

 15                ,                  Comma operator                                                            Left to right