Simple Relational Operator Example Program In C++

Read About C++ Operators

Relational Operators

  • It compares two operands and depending on their relationship.

Syntax

Op1 Operator Op2

Example :

a > b

There are six relational operators. They are,

  • <  less than
  • >  greater than
  • <= less than or equal to
  • >= greater than or equal to
  • == equal to
  • != not equal to

Example of Relational Operator Program

// Header Files
#include<iostream>
#include<conio.h>

//Main Function

using namespace std;

int main ()
{
  	// Variable Declaration
	int a = 25, b = 5;
	//int a = 5, b = 25;
	//int a = 5, b = 5;	
	
	cout << "Simple Relational Operator Example Program \n";
	
	if( a>b )
		cout<<"A is Big";
	else if( a== b)
		cout<<"A and B are Equal";
	else
		cout<<"B is Big";

	// Wait For Output Screen
	getch();

	//Main Function return Statement
	return 0;
}

Sample Output

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