# XOR truth table

• 02-08-2006
swgh
XOR truth table
I created an XOR true table using some of my old C language knowledge,

I showed my tutor and he said that creating such a table is considered redundent, but others argue it can be used to inplement C++'s flexability.

Here is the coce... What do you guys think about my tutors comment and the argument in general?

Personally, I think it is rather helpful.

Code:

```#include <iostream> using std::cout; using std::endl; // main function int _tmain(int argc, _TCHAR* argv[]) {         bool p, q;         p = true;         q = true;         cout << p << " XOR " << q << " is " <<                 ( ( p || q ) && !( p && q ) ) << "\n";         p = false;         q = true;         cout << p << " XOR " << q << " is " <<                 ( ( p || q ) && !( p && q ) ) << "\n";         p = true;         q = false;         cout << p << " XOR " << q << " is " <<                 ( ( p || q ) && !( p && q ) ) << "\n";         p = false;         q = false;         cout << p << " XOR " << q << " is " <<                 ( ( p || q ) && !( p && q ) ) << "\n";         getchar();        // freeze output         return 0;        // indicatres sucsessful termination }```
• 02-08-2006
ZuK
Since C/C++ has the ^ operator, doing it your way can be considered redundant.
Kurt
• 02-08-2006
jwenting
but then students more often than not get assignments that amount to implementing something that's available in the standard library (like lists, stacks, queues, etc.) ;)

But get rid of those compiler specific things in there. Anything starting with an underscore is suspect by definition :)
• 02-08-2006
swoopy
>What do you guys think about my tutors comment and the argument in general?
I like the code because it demonstrates how you'd implement xor if your language didn't have such an operator.
• 02-08-2006
Dave_Sinkula
If the input type were int rather than bool, it also shows how you could do a logical xor rather than a bitwise xor. Of course, it can be more simply written as p != q.