As you can see here, the |
operator has a higher precedence than the assignment operator =
. Therefore, when you don’t wrap (a = false)
in parentheses :
if (a = false | (b = false) || (c = true) | (d = true))
is equivalent to
if (a = (false | (b = false) || (c = true) | (d = true)))
so you are assigning true
to a
.
On the other hand, in
if ((a = false) | (b = false) || (c = true) | (d = true))
you are assigning false
to a
.
solved Why is this boolean variable assigned true?