4.Relational Operators
When you want to compare two values in terms of operands, this operator is used.
List of
relational operators:
‘==’ – it
checks that both operands are equal or not.
‘>’ – it
checks the first operand is greater than the second operand.
‘<’ – it
checks the first operand is less than or not.
‘>=’ –
it checks for greater than or equal to
‘<=’ –
it checks for less than or equal to
‘!=’ -it
checks for not equal
The c++ program example is given below.
#include <iostream>
using namespace std;
int main() {
int x = 6, y = 4;
// checks for
Equal operator
cout <<
"x == y is " << (x == y) << endl;
// checks for x is
Greater than y
cout <<
"x > y is " << (x > y) << endl;
// checks for
Greater than Equal
cout <<
"x >= y is " << (x >= y) << endl;
//
Less than value checking
cout <<
"x < y is " << (x < y) << endl;
// checks for Less
than or Equal
cout <<
"x <= y is " << (x <= y) << endl;
// checks for not
equality
cout <<
"x != y is " << (x != y);
return 0;
}
Output:
x == y is 0
x > y is 1
x >= y is 1
x < y is 0
x <= y is 0
x != y is 1
Hope, this code will help you to understand the concept easily. Keep coding!!!
Comments
Post a Comment