I need to know how the logical AND an OR operators are evaluated in a statement. I have found a few sites that try to explain it but I can’t make heads nor tails of them. I know I can use braces to order it how I want but i’d like to understand how it works.
for example would
if( b1 && b2 || b3 )
be evaluated as:
(b1 && b2) || b3
or as:
b1 && (b2 || b3)
You can find in any operator precedence table that
&&has higher precedence than||, which means it’s evaluated asNote though that both
&&and||are short-circuiting, which means thatb2andb3don’t have to be evaluated. For example, ifb1evaluates tofalse,b2will not be evaluated at all. Also, ifb1 && b2evaluates totrue,b3won’t be evaluated.