home page > Programmer development tools > Operator Priority Comparison Table

Operator Priority Comparison Table

Java operator priority
operator priority
postfix expr ++ expr --
unary ++ expr -- expr + expr - expr ~ !
multiplicative * / %
additive + -
shift << >> >>>
relational < > <= >= instanceof
equality == !=
bitwise AND &
bitwise exclusive OR ^
bitwise inclusive OR |
logical AND &&
logical OR ||
ternary ? :
assignment = += -= *= /= %= &= ^= |= <<= >>= >>>=
C++operator priority
Precedence Operator Description Associativity
one :: Scope resolution Left-to-right
two ++    -- Suffix/postfix increment and decrement
() Function call
[] Array subscripting
. Element selection by reference
−> Element selection through pointer
three ++    -- Prefix increment and decrement Right-to-left
+    Unary plus and minus
!    ~ Logical NOT and bitwise NOT
( type ) Type cast
* Indirection (dereference)
& Address-of
sizeof Size-of
new , new[] Dynamic memory allocation
delete , delete[] Dynamic memory deallocation
four .*    ->* Pointer to member Left-to-right
five *    /    % Multiplication, division, and remainder
six +    Addition and subtraction
seven <<    >> Bitwise left shift and right shift
eight <    <= For relational operators < and ≤ respectively
>    >= For relational operators > and ≥ respectively
nine ==    != For relational = and ≠ respectively
ten & Bitwise AND
eleven ^ Bitwise XOR (exclusive or)
twelve | Bitwise OR (inclusive or)
thirteen && Logical AND
fourteen || Logical OR
fifteen ?: Ternary conditional Right-to-Left
sixteen = Direct assignment (provided by default for C++ classes)
+=    −= Assignment by sum and difference
*=    /=    %= Assignment by product, quotient, and remainder
<<=    >>= Assignment by bitwise left shift and right shift
&=    ^=    |= Assignment by bitwise AND, XOR, and OR
seventeen throw Throw operator (for exceptions)
eighteen , Comma Left-to-right
C language operator priority
Precedence Operator Description Associativity
one ++ -- Suffix/postfix increment and decrement Left-to-right
() Function call
[] Array subscripting
. Structure and union member access
−> Structure and union member access through pointer
( type ){ list } Compound literal (C99)
two ++ -- Prefix increment and decrement Right-to-left
+ Unary plus and minus
! ~ Logical NOT and bitwise NOT
( type ) Type cast
* Indirection (dereference)
& Address-of
sizeof Size-of
_Alignof Alignment requirement (C11)
three * / % Multiplication, division, and remainder Left-to-right
four + Addition and subtraction
five << >> Bitwise left shift and right shift
six < <= For relational operators < and ≤ respectively
> >= For relational operators > and ≥ respectively
seven == != For relational = and ≠ respectively
eight & Bitwise AND
nine ^ Bitwise XOR (exclusive or)
ten | Bitwise OR (inclusive or)
eleven && Logical AND
twelve || Logical OR
thirteen ?: Ternary conditional Right-to-Left
fourteen = Simple assignment
+= −= Assignment by sum and difference
*= /= %= Assignment by product, quotient, and remainder
<<= >>= Assignment by bitwise left shift and right shift
&= ^= |= Assignment by bitwise AND, XOR, and OR
fifteen , Comma Left-to-right
PHP operator priority
Binding direction operator Additional information
Disassociation clone new Clone and new
Left [ array()
Disassociation ++ -- Increment/decrement operator
Disassociation ~ - (int) (float) (string) (array) (object) (bool) @ type
Disassociation instanceof type
Dextral union ! Logical operator
Left * / % Arithmetic operator
Left + - . Arithmetic operators and string operators
Left << >> Bitwise Operators
Disassociation < <= > >= <> Comparison operator
Disassociation == != === !== Comparison operator
Left & Bitwise operators and references
Left ^ Bitwise Operators
Left | Bitwise Operators
Left && Logical operator
Left || Logical operator
Left ? : Ternary operator
right = += -= *= /= .= %= &= |= ^= <<= >>= Assignment Operators
Left and Logical operator
Left xor Logical operator
Left or Logical operator
Left , Used in many places

Python operator priority

This table gives Python operator priority (from low to high)
From the lowest priority (most loosely coupled) to the highest priority (most tightly coupled).
This means that in an expression, Python will first calculate the operators at the lower part of the table, and then calculate the operators listed at the upper part of the table.

operator describe
lambda Lambda expression
or Boolean OR
and Boolean AND
not x Boolean Not
in,not in Member Test
is,is not Identity test
<,<=,>,>=,!=,== compare
| Bitwise or
^ Bitwise XOR
& Bitwise and
<<,>> displacement
+,- addition and subtraction
*,/,% Multiplication, division and remainder
+x,-x Sign
~x Flip Bit
** index
x.attribute Attribute Reference
x[index] subscript
x[index:index] Addressing segment
f(arguments...) function call
(experession,...) Binding or tuple display
[expression,...] List display
{key:datum,...} Dictionary display
'expression,...' String conversion