C++ Comparison Operators Last Updated : 27 Nov, 2022 Comments Improve Suggest changes 1 Likes Like Report Comparison operators are operators used for comparing two elements, these are mostly used with if-else conditions as they return true-false as result. There are mainly 6 Comparison Operators namely: Greater than (>) : this operator checks whether operand1 is greater than operand2. If the result turns out to be true, it returns true or else returns false. example 5>3 ->returns trueGreater than or equal to (>=) : this operator checks whether operand1 is greater than or equal to operand2. If the result turns out to be true, it returns true or else returns false. example 5>=5 ->returns trueLess than (<) : this operator checks whether operand1 is lesser than operand2. If the result turns out to be true, it returns true or else returns false. example 3<5 ->returns trueLess than or equal to (< =) : this operator checks whether operand1 is lesser than or equal to operand2. If the result turns out to be true, it returns true or else returns false. example 5<=5 ->returns trueEqual to (==) : this operator checks whether operand1 is equal to operand2. If the result turns out to be true, it returns true or else returns false. example 5==5 ->returns trueNot Equal to (! =) : this operator checks whether operand1 is not equal to operand2. If the result turns out to be true, it returns true or else returns false. example 5!=3 ->returns true Comparison Operators have only two return values, either true (1) or False (0). Example Code to cover all 6 Comparison Operators: C++ // C++ Program to implement // comparison operators #include <iostream> using namespace std; int main() { int a, b; a = 5, b = 3; // example to demonstrate '>' operator if (a > b) cout << "a is greater than b" << endl; else cout << "a is not greater than b" << endl; a = 5, b = 5; // example to demonstrate '>=' operator if (a >= b) cout << "a is greater than or equal to b" << endl; else cout << "a is not greater than or equal b" << endl; a = 2, b = 3; // example to demonstrate '<' operator if (a < b) cout << "a is lesser than b" << endl; else cout << "a is not lesser than b" << endl; a = 2, b = 3; // example to demonstrate '<' operator if (a <= b) cout << "a is lesser than or equal to b" << endl; else cout << "a is not lesser than or equal to b" << endl; a = 5, b = 5; // example to demonstrate '==' operator if (a == b) cout << "a is equal to b" << endl; else cout << "a is not equal to b" << endl; a = 5, b = 3; // example to demonstrate '!=' operator if (a != b) cout << "a is not equal to b" << endl; else cout << "a is equal to b" << endl; return 0; } Outputa is greater than b a is greater than or equal to b a is lesser than b a is lesser than or equal to b a is equal to b a is not equal to b Create Quiz Comment R raj2002 Follow 1 Improve R raj2002 Follow 1 Improve Article Tags : Technical Scripter C++ Technical Scripter 2022 cpp-operator Explore C++ BasicsIntroduction to C++3 min readData Types in C++6 min readVariables in C++4 min readOperators in C++9 min readBasic Input / Output in C++3 min readControl flow statements in Programming15+ min readLoops in C++7 min readFunctions in C++8 min readArrays in C++8 min readCore ConceptsPointers and References in C++5 min readnew and delete Operators in C++ For Dynamic Memory5 min readTemplates in C++8 min readStructures, Unions and Enumerations in C++3 min readException Handling in C++12 min readFile Handling in C++8 min readMultithreading in C++8 min readNamespace in C++5 min readOOP in C++Object Oriented Programming in C++8 min readInheritance in C++6 min readPolymorphism in C++5 min readEncapsulation in C++3 min readAbstraction in C++4 min readStandard Template Library(STL)Standard Template Library (STL) in C++3 min readContainers in C++ STL2 min readIterators in C++ STL10 min readC++ STL Algorithm Library3 min readPractice & ProblemsC++ Interview Questions and Answers1 min readC++ Programming Examples4 min read Like