Operator precedence

1

Click here to load reader

Transcript of Operator precedence

Page 1: Operator precedence

Operator Precedence

Name Operator Direction Precedence

Parentheses () Left -> Right 1

Post-increment ++ Left -> Right 2

Post-decrement -- Left -> Right 2

Address & Right -> Left 2

Bitwise NOT ~ Right -> Left 2

Typecast (type) Right -> Left 2

Logical NOT ! Right -> Left 2

Negation - Right -> Left 2

Plus Sign + Right -> Left 2

Pre-increment ++ Right -> Left 2

Pre-decrement -- Right -> Left 2

Size of data sizeof Right -> Left 2

Modulus % Left -> Right 3

Multiplication * Left -> Right 3

Division / Left -> Right 3

Addition + Left -> Right 4

Subtraction - Left -> Right 4

Bitwise Shift Left << Left -> Right 5

Bitwise Shift Right >> Left -> Right 5

Less Than < Left -> Right 6

Less Than or Equal <= Left -> Right 6

Greater Than > Left -> Right 6

Greater Than or Equal >= Left -> Right 6

Equal == Left -> Right 7

Not Equal != Left -> Right 7

Bitwise AND & Left -> Right 8

Bitwise XOR ^ Left -> Right 9

Bitwise OR | Left -> Right 10

Logical AND && Left -> Right 11

Logical OR || Left -> Right 12

Condition Expression ?: Right -> Left 13

Assignment = Right -> Left 14

Additive Assignment += Right -> Left 14

Subtractive Assignment -= Right -> Left 14

Multiplicative Assignment *= Right -> Left 14

Divisional Assignment /= Right -> Left 14

Modulating Assignment %= Right -> Left 14

Left Shift Assignment >>= Right -> Left 14

Right Shift Assignment <<= Right -> Left 14

AND Assignment &= Right -> Left 14

XOR Assignment |= Right -> Left 14

OR Assignment ^= Right -> Left 14

Comma , Left -> Right 15