RELATIONAL OPERATORS

Let’s start with relational operators. In general there are 4 different operator that can be used for comparing the values of arithmetic expressions and they are given in the following table:
A < B
Value A is less then value B
A <= B
Value A is less then value B
A > B
Value A is greater than value B
A >= B
Value A is greater or equal to value B
What’s important to understand is that in each case a comparison of operands on left and right is carried out and result is BOOLEAN OPERATORS. Let’s try an example by writing a following code.

#include "stdafx.h"
#include "iostream"
using namespace std;


int _tmain(int argc, _TCHAR* argv[])
{
       bool b1;
       b1 = 2 > 1; //Assign true Result is 1
       cout << b1 << "\n";
       b1 = 2 < 1; //Assign false Result is 0
       cout << b1 << "\n";
       b1 = 2 >= 2; //Assign true Result is 1 
       cout << b1 << "\n";
       b1 = 3.4 <= 2.4; //Assign false Result is 0
       cout << b1 << "\n";
       system("pause");
       return 0;
}
The result is shown in the following figure.
FIGURE - RESULT IN COMMAND PROMPT WINDOW
You may have been surprised to get the output result 1 or 0 for the results of the previous exercise. The point is that by default the values true and false are printed as 1 and 0. 
Share on Google Plus