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

getch();
                  }

                  Program 7: To use postfix increment/decrement operators.
                  #include<iostream.h>                        DOSBox 0.74, Cpu speed: max 100% cycles, Frames 0, Program:
                  #include<conio.h>                        The old value of a is: 10
                                                           The value of a after postfix increment is: 11
                  void main()
                                                           The value of b is: 10
                  {                                        The value of a after postfix decrement is: 10
                      clrscr();                            The value of c is: 11
                      int a = 10, b = 0, c = 0;

                      cout << "The old value of a is: " << a << "\n";


                      // Postfix Increment
                      b = a++;   // Value is assigned first, then incremented
                      cout<< "The value of a after postfix increment is: " << a << "\n";
                        cout<< "The value of b is: " << b << "\n";



                      // Postfix Decrement
                        c = a--;   // Value is assigned first, then decremented
                        cout<< "The value of a after postfix decrement is: " << a << "\n";

                        cout<< "The value of c is: " << c << "\n";
                        getch();
                  }
                  Ternary Operator

                  A ternary operator requires three operands to work. In C++, there is only one ternary operator
                  (?:).  It is also called conditional operator. The syntax of the ternary operator is:

                  conditional_expression ? expression1 : expression2;
                  where,
                      conditional_expression is an expression that evaluates to true or false.

                      If conditional_expression is true, then expression1 is executed.
                      If conditional_expression is false, then expression2 is executed.
                  Program 8: To check the greatest in two numbers.

                  #include<iostream.h>
                  #include<conio.h>
                  void main()

                  {
                      clrscr();
                      int a, b;
                      a = 20;

                   36
                          Touchpad MODULAR (Ver. 2.0)
   33   34   35   36   37   38   39   40   41   42   43