Relational Operators in C++
Notes:
Relational Operators in C++ Programming Language:
Relational operators are also known as comparison operators.
They are used find the relationship between two values or compare the relationship between two values; on comparison they yield the result either 0 or 1.
Note: zero indicates FALSE and any non zero value indicates TRUE
- There are 6 relational or comparison operators in C++. They are
< : less than
> : greater than
<= : less than or equal to
>= : greater than or equal to
== : equal to
!= : not equal to
Note:
- OR says if both LHS & RHS operands are 0 then the result will be 0; otherwise the result will be 1
LHS RHS LHS OR RHS
1 1 1
1 0 1
0 1 1
0 0 0
Example Code:
#include <iostream>
using namespace std;
int main()
{
cout << (3<4) << endl; // 1
cout << (5<4) << endl; // 0
cout << (5>4) << endl; // 1
cout << (5>6) << endl; // 0
cout << (5<=6) << endl; // 1
cout << (5<=5) << endl; // 1
cout << (5<=4) << endl; // 0
cout << (5>=4) << endl; // 1
cout << (5>=5) << endl; // 1
cout << (5>=6) << endl; // 0
cout << (5!=6) << endl; // 1
cout << (5==6) << endl; // 0
return 0;
}