Everyone talked about operator precedence and lookup tables where you can see this. But I would like to give a hint how to remember this. If you think of false as 0 and true as 1 , then && as a multiplication, and || similar to addition (they are actually called logical multiplication and logical addition). The priority relation is the same: multiplication is higher than addition. It works the same way:
0 * 0 == 0 | false && false == false 0 * 1 == 0 | false && true == false 1 * 0 == 0 | true && false == false 1 * 1 == 1 | true && true == true 0 + 0 == 0 | false || false == false 0 + 1 == 1 | false || true == true 1 + 0 == 1 | true || false == true 1 + 1 == 1* | true || true == true
(*) actually 2 limited to 1
And usually when in doubt, use parentheses.
source share