Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which has more priority: || or && or ==

I have this expression:

y[i] = ( z[i] == a && b || c )

Which of these elements (&&, ||, ==) have the priority?

Can you please show the order of operations with brackets?

like image 411
Giovanni Genna Avatar asked Nov 07 '15 14:11

Giovanni Genna


People also ask

Which has priority || or &&?

The logical-AND operator ( && ) has higher precedence than the logical-OR operator ( || ), so q && r is grouped as an operand.

Which operator has the lowest priority || ++?

D) | | - This operator falls under the category of Logical OR and has the lowest priority as compared to all the above-mentioned operators.


3 Answers

First ==, then &&, then ||.

Your expression will be evaluated as y[i] = (((z[i] == a) && b) || c).

https://docs.oracle.com/javase/tutorial/java/nutsandbolts/operators.html

like image 176
André Chalella Avatar answered Oct 10 '22 14:10

André Chalella


The priority list:

  1. ==
  2. &&
  3. ||
like image 34
Alex Avatar answered Oct 10 '22 15:10

Alex


The actual expression is evaluated as

y[i] = ( ((z[i] == a) && b) || c )

You probably want to look here for more info on operator precedence. https://docs.oracle.com/javase/tutorial/java/nutsandbolts/operators.html

like image 32
Magnus Jørgensen Avatar answered Oct 10 '22 14:10

Magnus Jørgensen