Operator precedence
Operator precedence:
Which operator is performed first in an expression with more than one operators.
Operator:
Symbol that tells the compiler to perform specific mathematical function.
Operand:
On which operation is to be performed.
Example:
a = b * c;
Here a, b and c are operands.
* represents operator.
Associativity:
If two or more operators have some precedence then how we have to calculate by left to right or right to left.
How many types of Operators?
Operator Precedence and Associativity:
Which operator is performed first in an expression with more than one operators.
Operator:
Symbol that tells the compiler to perform specific mathematical function.
Operand:
On which operation is to be performed.
Example:
a = b * c;
Here a, b and c are operands.
* represents operator.
Associativity:
If two or more operators have some precedence then how we have to calculate by left to right or right to left.
How many types of Operators?
Operator Precedence and Associativity:
Precedence | Operator | Description | Associativity |
---|---|---|---|
1 | [] () . | Array index. Method call. Member access. | Left to Right. |
2 | ++ -- +- ~! | Prefix or Postfix increment. Prefix or Post fix decrement. Unary plus, minus. Bitwise NOT.Logical NOT. | Right to left. |
3 | (typecast). New. | Typecast. Object creation. | Right to left. |
4 | */% | Multiplication.Division.Remainder. | Left to Right. |
5 | +- + | Addition Subtraction. String Concatenation. | Left to Right. |
6 | << >> >>> | Left shift. Right shift. Zero fill right shift. | Left to Right. |
7 | < <= > >= instanceof | Less than. Less than or equal to. Greater than. Greater than or equal to. Reference test. | Left to right. |
8 | == != | Equal to. Not equal to. | Left to Right. |
9 | & | Bitwise AND. | Left to Right. |
10 | ^ | Bitwise XOR. | Left to Right. |
11 | | | Bitwise OR. | Left to Right. |
12 | && | Logical AND. | Left to Right. |
13 | || | Logical OR. | Left to Right. |
14 | ?: | Ternary. | Right to Left. |
15 | =+=-=*=/=%=&=|=^=<<=>>= >>>= | Assignment and short hand assignment. | Right to Left. |