The result of 8 == 8
when converted to int
is 1
.
a & 8 == 8
thus becomes a & 1
, which is true if the least significant bit of a
is set. This would only be true of a
is odd.
Since a
is 10, then a & 1
is 0
, since 10 is even.
The &
in this case is a bitwise-and and not a logical-and. A logical-and would have resulted in the expression a && 8 == 8
being true, since both sides of the &&
operator would have been non-zero.
However, the bitwise-and produces a result in which "each bit in the result is set if and only if each of the corresponding bits in the converted operands is set" (C.11 §6.5.10 ¶4). For an even number, the 1
s bit is 0
, so the result of bitwise-and with 1
is 0
.
Since the result of the bitwise-and is 0
, the expression is treated as false.