Do logical operators have precedence in C (like &&
being executed after ||
or vice-versa) or do they execute from left to right? I usually use parentheses to make sure they execute correctly, but someone asked me about this and I was not sure.
For example is a || b && c == 2
interpreted as (((a || b) && c) == 2)
or (a ||( b && (c == 2)))
The condition is interpreted as (a ||( b && (c == 2)))
The &&
have a higher priority over the ||
, as you can see here : https://en.cppreference.com/w/c/language/operator_precedence