Why is there no “logical exclusive or” operator?
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”.