C++ Operator Precedence and Associativity

As I am too lazy to always look this up in the book, I have typed it in.

Stanley B. Lippman
C++ Primer (2nd Edition)
Addision Wesley


Level Operator Function
17R :: global scope (unary)
17L :: class scope (binary)
16L -> , . member selectors
16L [] array index
16L () function call
16L () type construction
15R sizeof size in bytes
15R ++ , -- increment, decrement
15R ~ bitwise NOT
15R ! logical NOT
15R + , - uniary minus, plus
15R * , & dereference, address-of
15R () type conversion (cast)
15R new , delete free store management
14L ->* , .* member pointer selectors
13L * , / , % multiplicative operators
12L + , - arithmetic operators
11L << , >> bitwise shift
10L < , <= , > , >= relational operators
9L == , != equaltity, inequality
8L & bitwise AND
7L ^ bitwise XOR
6L | bitwise OR
5L && logical AND
4L || logical OR
3L ?: arithmetic if
2R = , *= , /= , %= , += , -=
<<= , >>= , &= , |= , ^=
assignment operators
1L , comma operator

Table 2.4 Operator Precedence and Associativity


jmayer@informatik.uni-kl.de