Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

Why is there no “logical exclusive or” operator?

exclusive operator
0
Posted

Why is there no “logical exclusive or” operator?

0

C has “bitwise and” (&), “bitwise or” (|), and “bitwise exclusive or” (^) operators. C also has “logical and” (&&) and “logical or” (||) operators. On the other hand, it has no “logical exclusive or” operator (presumably ^^), a decidedly asymmetrical lack. But there are at least a few reasons for its absence: • The evaluation of && is “short-circuited” if its left operand evaluates to zero, meaning that in that case, its right-hand operand need not (and may not) be evaluated. The same holds true for || when its left operand evaluates as nonzero. But a ^^ operator could not short-circuit, because its result cannot be known on the basis of either operand alone. • a ^^ b is easily written in terms of existing operators as !a != !b. If a and b are both known to be exactly 0 or 1, then it can be written even more simply as a != b. • “Logical exclusive or” is useful much less often than either “logical or” or “logical and”.

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123