C++ Operator Priority


C++ operator priority describes the order in which operations are performed when a computer evaluates an expression. Operations with higher priority are performed first, and then operations with lower priority are performed. For example, we often say that multiplication and division are performed first, and then addition and subtraction operations are performed.

C++ operator priority table, from top to bottom, from left to right, the priority decreases.
Precedence Operator Description Associativity
1 :: Range resolution From left to right
2 ++  -- Suffix increment/suffix decrement
() Parenthesis
[] Array subscript
. Member selection (object)
−> Member selection (pointer)
3 ++  -- Prefix increment/prefix decrement From right to left
+  − Add/subtract
!  ~ Logical NOT/Bitwise INVERSE
(type) Force type conversion
* Get the value pointed to by the pointer
& The address of something
sizeof The size of something
new,new[] Dynamic memory allocation/dynamic array memory allocation
delete,delete[] Dynamic memory release/dynamic array memory release
4 .*  ->* Member object selection/member pointer selection From left to right
5 *  /   % Multiplication/Division/Remainder
6 +  − Plus/Minus
7 <<  >> Bit shift left/Bit shift right
8 <  <= Less than/Less than or equal to
>  >= Greater than/Greater than or equal to
9 ==  != Equal to/Not equal to
10 & Bitwise AND
11 ^ Bitwise XOR
12 | Bitwise OR
13 && AND operation
14 || OR operation
15 ?: Ternary operator Right to left
16 = Assignment
+=  −= Addition and assignment
|| OR operation
15 ?: Ternary operator Right to left
16
*=  /=   %= Multiplication postfix/Division postfix/Remainder postfix
<<=  >>= Bitwise left shift postfix/Bitwise right shift postfix
&=  ^=  |= Bitwise AND postfix/Bitwise XOR postfix/Bitwise OR postfix
17 throw Throw out the exception
18 , Comma From left to right