In many cases, an expression may contain different type of operators, such as the one shown here.

PHP

$a * $b + 2 > 21 || !($c == $b / 2) && $c > 13

In such cases, arithmetic operations are performed first, comparison operations are performed next, and logical operations are performed at the end, as shown in the following table

Higher Precedence

arrow_up

Lower Precedence

Arithmetic Operators

*, /, %

+, -

Comparison Operators

<, <=, >, >=, ==, !=

Logical Operators

!

&&

||

Java, C++, C#

a * b + 2 > 21 || !(c == b / 2) && c > 13

In such cases, arithmetic operations are performed first, comparison operations are performed next, and logical operations are performed at the end, as shown in the following table

Higher Precedence

arrow_up

Lower Precedence

Arithmetic Operators

*, /, %

+, -

Comparison Operators

<, <=, >, >=, ==, !=

Logical Operators

!

&&

||

Visual Basic

a * b + 2 > 21 Or Not(c = b / 2) And c > 13

In such cases, arithmetic operations are performed first, comparison operations are performed next, and logical operations are performed at the end, as shown in the following table

Higher Precedence

arrow_up

Lower Precedence

Arithmetic Operators

^

*, /, \, Mod

+, -

Comparison Operators

<, <=, >, >=, =, <>

Logical Operators

Not

And

Or

Python

a * b + 2 > 21 or not(c == b / 2) And c > 13

In such cases, arithmetic operations are performed first, comparison operations are performed next, and logical operations are performed at the end, as shown in the following table

Higher Precedence

arrow_up

Lower Precedence

Arithmetic Operators

**

*, /, //, %

+, -

Comparison and Membership Operators

<, <=, >, >=, ==, !=, in, not in

Logical Operators

not

and

or

Leave a Reply

Your email address will not be published. Required fields are marked *

This article is taken from a book of mine. If you enjoyed it, please visit my author's page inand check out all of my books!