Relational Operator In C++

Definition: Relational Operators ? Use of the Relational Operators

The relational operators are binary operators .In c++, Relational operators specify the relation between two variables by comparing them. There are 5 relational operators in C.


Use of the Relational Operators

A relational operator tests data values against one another.

You can only compare similar data types. (It makes no sense to compare a char to a float.

All relational operators return either a 1 (meaning true) or a 0 (false.)

You will use the relational operators to test whether a condition is true or false and act accordingly.


Relational Operators

Operator Description Example
== Is equal to a==b
!= Is not equal to a!=b
> Greater than a>b
< Less than a<b
>= Greater than or equal to a>=b
<= Less than or equal to a<=b

Example 1:

Output :

  Simple Arithmetic Operators Example
   a is smaller 
   a is less than/equal to c
   a is greater than/equal to c

Example 2:

Output :

Simple Arithmetic Operators Example
Simple Relational Operator Example Program
//if a = 25, b = 5;
A is Big
//if a = 5, b = 25;
B is Big
//if a = 5, b = 5;
B is Big