Relational Operators in C++

Relational Operators in C++
Techiio-author
Written by Sagar RabidasFebruary 6, 2022
8 min read
C++
0 VIEWS 0 LIKES 0 DISLIKES SHARE
0 LIKES 0 DISLIKES 0 VIEWS SHARE
Techiio-author
Sagar Rabidas

Software Developer

In this blog, we will discuss Relational Operators in C++

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
Was this blog helpful?
techiio-price-plantechiio-price-plantechiio-price-plantechiio-price-plantechiio-price-plan
You must be Logged in to comment
Code Block
Techiio-logo

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.

Follow us on:

Subscribe to get latest updates

You can unsubscribe anytime from getting updates from us
Developed and maintained by Wikiance
Developed and maintained by Wikiance