1. Home
  2. Computing & Technology
  3. C / C++ / C#

C++ Tutorial - About Expressions and Statements

By David Bolton, About.com

8 of 8

Table of Precedence Levels 5-18

5 (all binary)
5 * L-R Multiply
5 / Divide
5 ^ Modulus (remainder)
6 (all binary) + L-R Addition
6 - Subtraction
7 << L-R Left shift
7 >> Right shift
8 < L-R Less than
8 <= Less than or equal to
8 >= Greater than or equal to
8 > Greater than
9 == L-R Equal to
9 != Not equal to
10 (binary) & L-R Bitwise AND
11 ^ L-R Bitwise XOR (exclusive OR)
12 | L-R Bitwise OR
13 && L-R Logical AND
14 || L-R Logical OR
15 = R-L Simple assignment
15 *= Multiply and assign
15 /= Divide and assign
15 %= Take remainder and assign
15 += Add and assign
15 -= Subtract and assign
15 &= Bitwise AND assign
15 ^= Bitwise XOR assign
15 |= Bitwise OR assign
15 <<= Left shift assign
15 >>= Right shift assign
16 :? R-L Conditional
17 throw L-R Throw exception
18 , L-R Comma Operator

So re-examining these expressions:

  int y = c + a*b;
  int x = d + e/f;
The multiplication is level 5, higher than addition at level 6 so a*b is evaluated first then c added. Likewise e/f is done before d is added.

This completes this tutorial

Explore C / C++ / C#
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. C / C++ / C#
  4. C++
  5. Learn C++ Programming
  6. Table of Precedence Levels 5-18

©2009 About.com, a part of The New York Times Company.

All rights reserved.