C++ Operators

Unary

Name Syntax Return Value
Increment ++A A + 1
A++ A
Decrement ––A A - 1
A-- A

Binary

Name Syntax Assignment
Shortcut
Arithmetic A + B
A - B
A * B
A / B
Yes
Modulo (remainder) A % B Yes
Logical AND,
OR,
NOT
A && B
A || B
A ! B
No
Bitwise AND,
OR,
NOT,
XOR
A & B
A | B
A ~ B
A ^ B
Yes
Bit Shift Left,
Right
num << n
num >> n
Yes
Comparison A < B
A > B
A <= B
A >= B
A == B
A != B
No

Notes




Ternary

Name Syntax
Conditional condition ? ResultIfTrue : ResultIfFalse

Precedence Order

Operators Usage Associativity
:: Scope Resolution Left
() [] -> .  Left
! ~ + (unary) - (unary) ++ –– & (unary) Logical NOT; Bitwise NOT; Arithmetic sign; Increment; Decrement; AddressOf Right
* (unary) (typecast) static_cast Pointer dereferencing; casting Right
const_cast dynamic_cast reinterpret_cast Casting Right
sizeof new delete...typeid  Right
.* (unary) ->*  Left
* / % Arithmetic Left
+ - Arithmetic Left
<< >> Bitwise shift Left
< <= > >= Logical Comparison Left
== != Logical Comparison Left
& Bitwise logic Left
^ Bitwise logic Left
| Bitwise logic Left
&& Boolean Logic Left
|| Boolean Logic Left
?: Conditional operator Right
= *= /= %= += -= Assigment; Assignment shortcuts Right
&= ^= |= <<= >>= Assignment shortcuts Right
, (comma) Multiple statements Left

Notes

If there are no parenthesis in an expression, operators of equal precedence are executed in a sequence determined by their associativity. For operators with an associativity of left, the left-most operator is executed first; for operators with an associativity of right, the right-most operator is executed first.