Create an XOR using the C++ logical operators. : relational and logical operators « Operators statements « C++ Tutorial






#include <iostream> 
#include <cmath> 
 
using namespace std; 
 
int main() 
{ 
  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"; 
   
 
  return 0; 
}
1 XOR 1 is 0
0 XOR 1 is 1
1 XOR 0 is 1
0 XOR 0 is 0








3.2.relational and logical operators
3.2.1.The relational and logical operators
3.2.2.Use And operator to connect two boolean expressions
3.2.3.Logical operator keywords: and, or, not, not_eq
3.2.4.Create an XOR using the C++ logical operators.
3.2.5.Output the results of several variable comparisons.
3.2.6.A Demonstration of Branching Based on Relational Operators