Page 34 - Modular_V2.0_C++_Flikpbook
P. 34

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 is         x < y        FALSE
                                               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()
                                                            DOSBox 0.74, Cpu speed: max 100% cycles, Frames 0, Program:
                  {
                                                        Result of equal to operator is: 0
                      clrscr();                         Result of greater than operator is: 1
                      int a, b;                         Result of less than operator is: 0
                      a = 75;                           Result of greater than equal to operator is: 1
                                                        Result of less than equal to operator is: 0
                      b = 65;
                                                        Result of not equal to operator is: 1_

                      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';
                   32
                          Touchpad MODULAR (Ver. 2.0)
   29   30   31   32   33   34   35   36   37   38   39