Logical Operators in C

前端 未结 8 2029
说谎
说谎 2020-11-27 08:25

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

8条回答
  •  自闭症患者
    2020-11-27 09:25

    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.

提交回复
热议问题