I am having trouble trying to understand how logical operators work in C. I already understand how the bit-level operators work, and I also know that logical operators treat
The &&
is a logical AND
(as opposed to &
, which is a bitwise AND
). It cares only that its operands as zero/non-zero values. Zeros are considered false
, while non-zeros are treated as true
.
In your case, both operands are non-zero, hence they are treated as true
, resulting in a result that is true
as well. C represents true
as 1
, explaining the overall result of your operation.
If you change the operation to &
, you would get a bitwise operation. 0x65 & 0x55
will give you a result of 0x45
.