What is the point of the logical operators in C?

后端 未结 5 1993
被撕碎了的回忆
被撕碎了的回忆 2020-12-18 07:49

I was just wondering if there is an XOR logical operator in C (something like && for AND but for XOR). I know I can split an XOR into ANDs, NOTs and ORs but a simple

5条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-18 08:11

    In C arguments of logical operators are treated as Boolean values - anything zero is treated as "false", and anything else (yes, negative values too) are "true". Bitwise ops work on individual bits, and as Neil already noted, are not subject to short-circuit evaluation as logical ops are.

    In your example the results are totally valid and expected since bit-wise xor between two ones is zero.

提交回复
热议问题