# Relational Operators in C++  Written by Sagar RabidasFebruary 6, 2022
C++
0 VIEWS 0 LIKES 0 DISLIKES SHARE
0 LIKES 0 DISLIKES 0 VIEWS SHARE Sagar Rabidas

Software Developer

## Relational Operators in C++

Relational operators also are called evaluation operators. Relational operators are used to touching on the condition, this is it compares the two values and prints the result. In this newsletter, we are going to see the ones, relational operators, in c++ with the help of examples.

## Different Relational Operators in C++

There are total 6 relational operators ==, !=, <, >,<=, >= which are explained below:

• Less than Operator (<):-

This operator is called less-than the operator. It checks whether the value of the left operand is less than the value of the right operand or not. If it satisfies the condition then, it returns true as a value else it returns false.

• Greater than Operator (>):-

This operator is called greater than the operator. It checks whether the value of the left operand is greater than the value of the right operand. If it satisfies the condition it returns true as value else it returns false.

• Less than or Equal to Operator (<=):-

This operator is called less than or equal to the operator. It checks whether the value of the left operand is less than or equal to the value of the right operand. If it satisfies the condition it returns true as value else it returns false.

• Greater than or Equal to Operator (>=):-

This operator is called greater than or equal to the operator. It checks whether the value of the left operand is greater than or equal to the value of the right operand. If it satisfies the condition it returns true as value else it returns false.

• Equal to Operator (==):-

This operator is called as is equal to the operator. It checks whether the value of the left operand is equal to the value of the right operand. If it satisfies the condition it returns true as value else it returns false.

• Not Equal to Operator (!=):-

This operator is called as is not equal to the operator. It checks whether the value of the left operand is not equal to the value of the right operand. If it satisfies the condition it returns true as value else it returns false.

## Examples of Relational Operators in C++

Below are the different examples of relational operators in C++:

### Example #1

An example to implement greater than operator is as follows.

#### Code:

`#include <iostream>`
`using namespace std;`
`int main()`
`{`
`int X, Y;`
`cout << "Enter the value of X: ";`
`cin >> X;`
`cout << "Enter the value of Y: ";`
`cin >> Y;`
`if(X > Y)`
`{`
`cout << "X is greater than Y";`
`}`
`else`
`{`
`cout << "Y is greater than X";`
`}`
`return 0;`
`}`

### Example #2

An example to implement less than the operator is as follows.

#### Code:

`#include <iostream>`
`using namespace std;`
`int main()`
`{`
`int X, Y;`
`cout << "Enter the value of X: ";`
`cin >> X;`
`cout << "Enter the value of Y: ";`
`cin >> Y;`
`if(X < Y)`
`{`
`cout << "X is less than Y";`
`}`
`else`
`{`
`cout << "Y is less than X";`
`}`
`return 0;`
`}`

### Example #3

An example to implement greater than or equal to the operator is as follows.

#### Code:

`#include <iostream>`
`using namespace std;`
`int main()`
`{`
`int X, Y;`
`cout << "Enter the value of X: ";`
`cin >> X;`
`cout << "Enter the value of Y: ";`
`cin >> Y;`
`if(X >= Y)`
`{`
`cout << "X is greater than or equal to Y";`
`}`
`else`
`{`
`cout << "Y is greater than or equal to X";`
`}`
`return 0;`
`}`

### Example #4

An example to implement less than or equal to the operator is as follows.

#### Code:

`#include <iostream>`
`using namespace std;`
`int main()`
`{`
`int X, Y;`
`cout << "Enter the value of X: ";`
`cin >> X;`
`cout << "Enter the value of Y: ";`
`cin >> Y;`
`if(X <= Y)`
`{`
`cout << "X is less than or equal Y";`
`}`
`else`
`{`
`cout << "Y is less than or equal to X";`
`}`
`return 0;`
`}`

### Example #5

An example to implement equally to the operator is as follows.

#### Code:

`#include <iostream>`
`using namespace std;`
`int main()`
`{`
`int X, Y;`
`cout << "Enter the value of X: ";`
`cin >> X;`
`cout << "Enter the value of Y: ";`
`cin >> Y;`
`if(X == Y)`
`{`
`cout << "X is equal to Y";`
`}`
`else`
`{`
`cout << " X is not equal to y";`
`}`
`return 0;`
`}`

### Example #6

An example to implement not equal to an operator is as follows.

#### Code:

`#include <iostream>`
`using namespace std;`
`int main()`
`{`
`int X, Y;`
`cout << "Enter the value of X: ";`
`cin >> X;`
`cout << "Enter the value of Y: ";`
`cin >> Y;`
`if(X != Y)`
`{`
`cout << "Condition is true";`
`}`
`else`
`{`
`cout << "condition is false";`
`}`
`return 0;`
`}`

C
C++
Relational Operators
0 VIEWS 0 LIKES 0 DISLIKES SHARE
0 LIKES 0 DISLIKES 0 VIEWS SHARE     You must be Logged in to comment
Code Block Sagar Rabidas
Software Developer     +9 more
300 Blog Posts
Trending Technologies
15 Software91 DevOps48 Frontend Development24 Backend Development20 Server Administration17 Linux Administration28 Data Center24 Sentry24 Terraform23 Ansible83 Docker70 Penetration Testing16 Kubernetes21 NGINX20 JenkinsX17
Recommended Blogs
8        8 Anik Adhikary Anik Adhikary Anik Adhikary Anik Adhikary Anik Adhikary Anik Adhikary Anik Adhikary Anik Adhikary Techiio is on the journey to build an ocean of technical knowledge, scouring the emerging stars in process and proffering them to the corporate world.