Page 26 - Modular_V1.1_Flipbook
P. 26

Relational Operators

                  Relational operators are used to compare the value of the two operands and return True or
                  False accordingly. They are binary operators as they need two operands to work. C++ provides
                  the following relation operators:

                    Operator        Name                      Description                     Example        Output
                                                                                           (x=8 and y=6)
                       ==       Equal to        It checks if the values of two operands        x == y         FALSE
                                                are equal and returns True if both are
                                                equal otherwise false.
                        !=      Not equal to    It checks if the values of two operands         x != y        TRUE
                                                are not equal and returns false if both
                                                are equal.
                        >       Greater than    It checks if the value of left operand is       x > y         TRUE
                                                greater than the value of right operand.
                        <       Less than       It checks if the  value  of  left operand       x < y         FALSE
                                                is less than the value of right operand.
                       >=       Greater  than  It checks if the value of left operand is       x >= y         TRUE
                                or equal to     greater than or equal to the value of
                                                right operand.
                       <=       Less than or  It checks if the value of left operand is        x <= y         FALSE
                                equal to        less than or equal to the value of right
                                                operand.
                    Clickipedia



                     In C++, the non-zero value is treated as true and zero value is treated as false.


                  Program 3: To use all the relational operators.

                  #include<iostream.h>
                  #include<conio.h>
                  void main(){
                  int a, b;
                  a = 75;
                  b = 65;
                  clrscr();
                  cout<<”Result of equal to operator is: “ << (a == b) << ‘\n’;
                  cout<<”Result of greater than operator is: “ << (a > b) << ‘\n’;
                  cout<<”Result of less than operator is: “ << (a < b) << ‘\n’;
                  cout<<”Result of greater than equal to operator is: “ << (a >= b) << ‘\n’;

                  cout<<”Result of less than equal to operator is: “ << (a <= b) << ‘\n’;
                  cout<<”Result of not equal to operator is: “ << (a != b);
                  getch();
                  }

                  24      Touchpad MODULAR (Version 1.1)-X
   21   22   23   24   25   26   27   28   29   30   31