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++:
- Equal to (==): The equal to operator is used to check if two values are equal.
Example:
refegi:ot riftidea.comint a = 5, b = 10; bool c = (a == b); // c is assigned the value false
- 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
- 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
- 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
- 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
- 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.