C++ Operators

This table lists all the operators in C++, grouping them by order of precedence . The higher-level precedence operators are evaluated before the lower-level precedence operators. For example, in the expression (a-b*c), the *, operator will be evaluated first and the - operator second, because * has precedence level 13 which is higher than the level 12 precedence of -. The column labeled "Assoc." tells whether an operator is right associative or left associative. For example, the expression (a-b-c) is evaluated as ((a-b)-c) because - is left associative. The column labeled "Arity" tells whether an operator operates on one, two, or three operands (unary, binary, or ternary). The column labeled "Overld" tells whether an operator is overloadable.

Operator Description Prec. Assoc.Arity Overld Example
: :Global scope resolution17RightUnaryNo::x
: :Class scope resolution17LeftBinaryNoX::x
.Direct member selection16LeftBinaryNos.len
->Indirect member selection16LeftBinaryYesp->len
[]Subscript16LeftBinaryYesa[i]
()Function call16Leftn/aYesabs(n)
()Type construction16Leftn/aYesint(ch)
++Post-increment16RightUnaryYesn++
--Post-decrement16RightUnaryYesn--
sizeofSize of object or type15RightUnaryNosizeof(a)
++Pre-increment15RightUnaryYes++n
--Pre-decrement15RightUnaryYes--n
~Bitwise NOT15RightUnaryYes~s
!Logical NOT15RightUnaryYes!p
+Positive15RightUnaryYes+n
-Negative15RightUnaryYes-n
*Dereference15RightUnaryYes*p
&Address15RightUnaryYes&x
newAllocation15RightUnaryYesnew p
deleteDeallocation15RightUnaryYesdelete p
()Type conversion15RightBinaryYes(int)ch
.*Direct member selection14LeftBinaryNox.*q
->*Indirect member selection14LeftBinaryYesp->*q
*Multiplication13LeftBinaryYesm * n
/Division13LeftBinaryYesm / n
%Remainder13LeftBinaryYesm % n
+Addition12LeftBinaryYesm + n
-Subtraction12LeftBinaryYesm - n
<<Bit shift left11LeftBinaryYescout << n
>>Bit shift right 11LeftBinaryYescin >> n
<Less than10LeftBinaryYesx < y
<=Less than or equal to10LeftBinaryYesx <= y
>Greater than10LeftBinaryYesx > y
>=Greater than or equal to10LeftBinaryYesx >= y
==Equal to9LeftBinaryYesx == y
!=Not equal to9LeftBinaryYesx != y
&Bitwise AND8LeftBinaryYess & t
^Bitwise XOR7LeftBinaryYess ^ t
|Bitwise OR6LeftBinaryYess | t
&&Logical AND5LeftBinaryYesu && v
||Logical OR4LeftBinaryYesu || v
? :Conditional expression3LeftTernaryNo u ? x : y
=Assignment2RightBinaryYesn = 22
+=Addition assignment2RightBinaryYesn += 8
-=Subtraction assignment2RightBinaryYesn -= 4
*=Multiplication assignment2RightBinaryYesn *= -1
/=Division assignment2RightBinaryYesn /= 10
%=Remainder assignment2RightBinaryYesn %= 10
&=Bitwise AND assignment2RightBinaryYes s &= mask
^=Bitwise XOR assignment2RightBinaryYess ^= mask
|=Bitwise OR assignment 2RightBinaryYess |= mask
<<=Bit shift left assignment2RightBinaryYess <<= 1
>>=Bit shift right assignment2RightBinaryYess >>= 1
throwThrow exception1RightUnaryYes throw(22)
,Comma0 LeftBinaryYes ++m, --n