Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 145 - CoreGPT(Podar)_Flipbook_C8
P. 145

    q = 2;

                         r = 4;
                         s = 9;
                         cout<<"Result of && operator is: " << ((p>q) && (q>r))<<"\n";
                         cout<<"Result of || operator is: " << ((p>q) || (q>r))<<"\n";
                         cout<<"Result of ! operator is: " << !((p>q) && (r==s))<<"\n";
                         getch();

                     }
                     Assignment Operators

                     Assignment operators are used to assign the value of the right-hand operand to the left-hand
                     operand.  These  operators  are  also  called  shorthand  assignment operators or  compound
                     assignment operators.

                     C++ provides the following assignment operators:

                      Operator              Name                             Description                     Example

                          =       Assignment                  It assigns the value of the right operand        x = 5
                                                              to the left operand.
                          +=      Addition assignment         It adds right operand to the left operand       x += 3
                                                              and  assigns  the  result  to  left  operand.
                                                              x+=3 is equivalent to x=x+3.
                          –=      Subtraction assignment It  subtracts  right  operand  from  the  left       x –= 3
                                                              operand  and  assigns  the  result  to  left
                                                              operand. x–=3 is equivalent to x=x–3.

                          *=      Multiplication              It  multiplies  right  operand  with  the  left   x *= 3
                                  assignment                  operand  and  assigns  the  result  to  left
                                                              operand. x*=3 is equivalent to x=x*3.
                          /=      Division assignment         It  divides  left  operand  with  the  right     x /= 3
                                                              operand  and  assigns  the  result  to  left
                                                              operand. x/=3 is equivalent to x=x/3.
                         %=       Remainder assignment        It  takes  modulus  of  two  operands  and      x %= 3
                                                              assigns the result to left operand. x%=3 is
                                                              equivalent to x=x%3.

                     Program 5: To use the assignment operators.

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

                         int a = 5, b = 7, c = 2, d = 10;

                                                                                      Developing Programs in C++        143

| 140 141 142 143 144 145 146 147 148 149 150 |