The following precedence chart is a simplified version of the table given in the operator summary of The C++ Programming Language, by Bjarne Stroustrup, the creator of C++.
Each box holds operators at the same precedence. Operators in higher boxes have higher precedence. Therefore, a + b * c means a + (b * c) not (a + b) * c. In the same way, a++ + i means (a++) + i.
Unary operators and assignment operators are right-associative; all other
operators are left-associative. Therefore, a = b = c means (a = (b = c), and
a + b + c means (a + b) + c.
Description | Operator | Use |
---|---|---|
scope resolution | :: | std::cout |
post increment post decrement |
++ -- |
k++ k-- |
pre increment pre decrement not unary minus unary plus |
++ -- ! - + |
++k --k ! isPrime() -5 +23 |
multiply divide modulo (remainder) |
* / % |
x * y i / j m % n |
add subtract |
+ - |
x + y i - j |
put get |
<< >> |
cout << k; cin >> i >> j; |
less than less than or equal greater than greter than or equal |
< <= > >= |
2 < 3 ch1 <= ch2 i > k x >= z |
equal not equal |
== != |
5 == num1 age != 65 |
AND | && | p && q |
OR | || | p || q |
conditional operator | ?: | (age < 21)? 0 : 1 |
assignment operators | = += -= . . . |
k = k + 1 k += 1 k -= 1 . . . |