C++ Comparison Operators Last Updated : 27 Nov, 2022 Comments Improve Suggest changes Like Article 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 Comment More infoAdvertise with us Next Article C++ Comparison Operators R raj2002 Follow Improve Article Tags : Technical Scripter C++ Technical Scripter 2022 cpp-operator Practice Tags : CPPcpp-operator Similar Reads Comparison Operators in LISP In this article, we will discuss the comparison operators in LISP. These operators are used to compare numbers by taking two or more operands. Note: This will work only on numbers, Different comparison operators are:OperatorSyntaxNameDescription== operand1 operand2equal toThis operator checks if the 4 min read Operators in C++ C++ operators are the symbols that operate on values to perform specific mathematical or logical computations on given values. They are the foundation of any programming language.Example:C++#include <iostream> using namespace std; int main() { int a = 10 + 20; cout << a; return 0; }Outpu 9 min read Excel VBA Comparison Operators VBA in Excel stands for Visual Basic for Applications which is Microsoft's programming language. To optimize the performance and reduce the time in Excel we need Macros and VBA is the tool used in the backend. Some helpful links to get more insights about Macros, VBA in Excel : 1. Record Macros in E 5 min read What are Comparison Operators in R? Comparison operators are fundamental tools in any programming language, allowing you to compare values and make decisions based on the results. In R Programming Language comparison operators are used to compare numeric, string, and other types of data. They return a logical value (TRUE or FALSE) bas 3 min read JavaScript Comparison Operators JavaScript comparison operators are essential tools for checking conditions and making decisions in your code. 1. Equality Operator (==) The Equality operator is used to compare the equality of two operands. JavaScript// Illustration of (==) operator let x = 5; let y = '5'; // Checking of operands c 5 min read Like