In C++ Programming, the values stored in two variables can be compared using following operators and relation between them can be determined. These operators are called relational operators. Various C++ relational operators available are −
| Operator | Description |
|---|---|
| > | Greater than |
| >= | Greater than or equal to |
| == | Is equal to |
| != | Is not equal to |
| < | Less than |
You can use these operators for checking the relationship between the operands. These operators are mostly used in conditional statements and loops to find a relation between 2 operands and act accordingly. For example,
Example
#include<iostream>
using namespace std;
int main() {
int a = 3, b = 2;
if(a < b) {
cout<< a << " is less than " << b;
}
else if(a > b) {
cout<< a << " is greater than " << b;
}
else if(a == b){
cout << a << " is equal to " << b;
}
return 0;
}Output
This will give the output −
3 is greater than 2