C++ Relational Operators
Overview
In this tutorial, we will learn about C++ relational operators with a sample program. Relational operators are used to evaluate conditions in the code.
C++ Relational Operators
Condition | Operator | Sample Example |
---|---|---|
Greater then | > | x > y |
Less than | < | x < y |
Greater than or Equal to | >= | x >= y |
Less than or Equal to | <= | x <= y |
Equal To | == | x == y |
Not Equal To | != | x != y |
Sample C ++ Program
/************************************ * C++ Relational Operators * Filename: relational.cpp * C++ Relational Operators Demo * program. * C++ Tutorials - www.TestingDocs.com **************************************/ #include using namespace std; int main() { //Declare two variables int x=20,y=5; // Print Statements bool result; cout << "1 = True | 0 = False" << endl; result = (x > y); cout << "Is x Greater Than y ? = " << result << endl; result = (x < y); cout << "Is x Less Than y ? = " << result << endl; result = (x >= y); cout << "Is x Greater Than Equal To y ? = " << result << endl; result = (x <= y); cout << "Is x Less Than Equal To y ? = " << result << endl; result = (x == y); cout << "Is x Equal To y ? = " << result << endl; result = (x != y); cout << "Is x Not Equal To y ? = " << result << endl; return 0; } // end main
Output
1 = True | 0 = False
Is x Greater Than y ? = 1
Is x Less Than y ? = 0
Is x Greater Than Equal To y ? = 1
Is x Less Than Equal To y ? = 0
Is x Equal To y ? = 0
Is x Not Equal To y ? = 1
That’s it.
—
C++ Tutorials
C++ Tutorials on this website:
https://www.testingdocs.com/c-coding-tutorials/
For more information on the current ISO C++ standard