C++ Relational Operators

Relational operators in C++ are used to compare two values and return a Boolean value (true or false) based on the relationship between them. The following are the relational operators in C++:

  1. Equal to (==): The equal to operator is used to check if two values are equal.

Example:

refe‮gi:ot r‬iftidea.com
int a = 5, b = 10;
bool c = (a == b); // c is assigned the value false
  1. Not equal to (!=): The not equal to operator is used to check if two values are not equal.

Example:

int a = 5, b = 10;
bool c = (a != b); // c is assigned the value true
  1. Greater than (>): The greater than operator is used to check if one value is greater than another.

Example:

int a = 10, b = 5;
bool c = (a > b); // c is assigned the value true
  1. Less than (<): The less than operator is used to check if one value is less than another.

Example:

int a = 5, b = 10;
bool c = (a < b); // c is assigned the value true
  1. Greater than or equal to (>=): The greater than or equal to operator is used to check if one value is greater than or equal to another.

Example:

int a = 10, b = 5;
bool c = (a >= b); // c is assigned the value true
  1. Less than or equal to (<=): The less than or equal to operator is used to check if one value is less than or equal to another.

Example:

int a = 5, b = 10;
bool c = (a <= b); // c is assigned the value true

In summary, relational operators in C++ are used to compare two values and return a Boolean value based on the relationship between them. The equal to (==), not equal to (!=), greater than (>), less than (<), greater than or equal to (>=), and less than or equal to (<=) operators are used to check for equality, inequality, greater than, less than, greater than or equal to, and less than or equal to relationships, respectively.