Comparison Operator in C++
It is use to compare two are variable for example if we have two variable and we want to check whether the two variable are equal are not equal or one of them is greater than other. So then we use Comparison operator. There are four Type of Comparison operators Equality Operator = = The double equal symbols is use to show the equality operator for example if we want to check whether the two variable are equal are not so we use equality operator to compare these variable.
For example
int a=5;
int b=6;
if(a==b)
cout<<"a and b are equal"<<endl;
There are three more Comparison Operator use in C++ which are given blew.
Less or Equal < =
Greater or Equal > =
Not Equal ! =
Example 1
#include<iostream.h>
int main()
{
int a=5;
int b=6;
if(a==b)
cout<<"a and b are equal"<<endl;
if(a!=b)
cout<<"a and b are not equal"<<endl;
system("pause");
return 0;
};
Example 2
#include<iostream.h>
int main()
{
int a=5;
int b=6;
if(a==b)
cout<<"a and b are equal"<<endl;
if(a>=b)
cout<<"a is greater then or equal to b"<<endl;
if(a<=b)
cout<<"a is less then or equal to b"<<endl;
system("pause");
return 0;
};
Example 3
#include<iostream.h>
int main()
{
int a=5;
int b=6;
if(a==b)
cout<<"a and b are equal"<<endl;
if(a!=b)
cout<<"a and b are not equal"<<endl;
system("pause");
return 0;
};