Relational and comparison operators in C++


In C Programming, the values keep in 2 variables can be compared using following operators and relation between them will be determined. These operators are called relational operators. Various C++ relational operators available are-

Operators Description
> Greater than
>= Greater than or equal to
== Is equal to
!= Is not equal to
<= Less than or equal to
< Less than

You can use these operators for checking the relationship between the operands. These operators are mostly used in conditional statements and loops to find a relation between 2 operands and act accordingly. For example,

Example

#include<iostream>
using namespace std;

int main() {
   int a = 3, b = 2;

   if(a < b) {
      cout<< a << " is less than " << b;
   }
   else if(a > b) {
      cout<< a << " is greater than " << b;
   }
   else if(a == b){
      cout << a << " is equal to " << b;
   }
   return 0;
}

Output

This will give the output −

3 is greater than 2

Updated on: 30-Jul-2019

343 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements