# Thread: Exclusive or in if statement?

1. ## Exclusive or in if statement?

Is it possible to use an Exclusive or in an if statment? I can't find any refference to it. Since bitwise or is | and Boolean or is || I tried
Code:
`if (a ^^ b)`
But that gives a syntax error.
It would make sense for this to be part of the c language so I'm guesing there is an obvious anser.

2. here, a logical exclusive or would be !=
an exclusive or returns 0 if both values are the same, and 1 if both the values are not equal( in terms of the truth tables taking 1,0 and considering all possible combos of a and b) if we consider != , if a is equal to b or vice versa, it will return 0, else it will return something other that 0, generally 1. so inside the if statement, != can be used as logical exclusive or.

3. thanx PING I never though of !=

4. In some cases, if you aren't particularly careful, that method could bite you (although, it is a fine solution). Note the following:

p xor q is equivalent to (p or q) and (not (p and q))

Work out the truth tables, and you'll see.

Popular pages Recent additions