Operator Precedence Chart

C++ uses the following precedence order for operators:

1.    [ ]         subscripting             left to right

       .          direct selection         left to right

      ->          indirect selection       left to right

    ++, --        postfix incr, decr       left to right

2.  ++, --         prefix incr, decr       right to left

    sizeof         size                    right to left

      !            logical not             right to left

      &            address of              right to left

      *            indirection             right to left

  (type name)      type cast               right to left

3.  *, /, %        multiplicative          left to right

4.   +, -          additive                left to right

5.  <, <=, >, >=   relational              left to right

6.  ==, !=         equality/inequality     left to right

7.   &&            logical and             left to right

8.   ||            logical or              left to right

9.  =, +=, -=,     assignment              right to left
     *=, /=

If two operators have the same precedence, the operand is grouped with the left or right operator according to whether the operators are evaluated left to right or right to left.


Email Me | Office Hours | My Home Page | Department Home | MCC Home Page

© Copyright Emmi Schatz 2003