The relational and logical operators : relational and logical operators « Operators statements « C++ Tutorial






#include <iostream> 
using namespace std; 
 
int main() {    
  int i, j; 
  bool b1, b2; 
 
  i = 10; 
  j = 11; 
  if(i < j) cout << "i < j\n"; 
  if(i <= j) cout << "i <= j\n"; 
  if(i != j) cout << "i != j\n"; 
  if(i == j) cout << "this won't execute\n"; 
  if(i >= j) cout << "this won't execute\n"; 
  if(i > j) cout << "this won't execute\n"; 
 
  b1 = true; 
  b2 = false; 
  if(b1 && b2) cout << "this won't execute\n"; 
  if(!(b1 && b2)) cout << "!(b1 && b2) is true\n"; 
  if(b1 || b2) cout << "b1 || b2 is true\n"; 
 
  return 0; 
}
i < j
i <= j
i != j
!(b1 && b2) is true
b1 || b2 is true








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