# Preview

# 6 Types of relational operators in C++

There are 6 Types of relational operators in C++. They are used to compare numeric values. These values may be in the form of literals or variables. The result of relational operator is either 1 or 0.

**i. < **

< is known as Less than operator. It checks whether a value is smaller than another value or not.

**Examples**

**1 < 3 = 1 //Result is 1 because 1 is less than 3**

**3 < 1 =**** 0 //Result is 0 because 3 is not less than 1**

**ii. <= **

**<= **is known as **Less Than Equal To **operator. It checks whether a value is smaller than or equal to another value or not.

**Examples**

**1 <= 3 =1 //Result is 1 because 1 is less than 3**

**3 <= 1 = 0 //Result is 0 because 3 is neither less than or equal to 1**

**4 <= 4 = 1 //Result is 1 because 4 is equal to 4**

** ****iii. >**

**> **operator is known as Greater than operator. It checks whether a value is larger than value or not.

**Examples**

**1 > 3 = 0 //Result is 0 because 3 is not less than 1**

**3 > 1 = 1 Result is 1 because 1 is less than 3**

**iv. >=**

**>= is Greater Than Equal To **operator. It checks whether a value is larger than or equal to another value.

**Examples**

**4 >= 2 =**** 1 //Result is 1 because 4 is more than 2**

**2 >= 4 = ****0 //Result is 0 because 2 is neither greater nor equal to 4**

**4 >= 4 = ****1 //Result is 1 because 4 is equal to 4**

**v. Equal To(==)**

**== (**double equal to) is known as equality operator. It checks whether a value is equal to another value or not.

**Examples**

**4 == 3 =**** 0 //Result is 0 because 4 is not equal to 3**

**10 == 10 =**** 1 //Result is 1 because 10 is equal to 10**

**vi. Not Equal To(!=) **

**!= **is known as **Not Equal To **operator ). It returns 1 if values being compared using this operator are not equal otherwise it returns 0.

**Examples**

**1 != 3 =****1 //Result is 1 because 1 is not same as 3**

**4 != 4=0**** //Result is 0 because 4 is equal to 4**

**//Program to demonstrate the use of relational operators.**

#include<iostream>using namespace std;int main(){int a=10,b=3;cout<<”\na>b=”<<(a>b);cout<<”\na>=b=”<<(a>=b);cout<<”\na<b=”<<(a<b);cout<<”\na<=b=”<<(a<=b);cout<<”\na==b=”<<(a==b);cout<<”\na!=b=”<<(a!=b);return 0;}

**Output**

a>b=1a>=b=1a<b=0a<=b=0a==b=0a!=b=1

**Popular Books of Computer Science**