Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 89 - 2625 PortGPt V2.1
P. 89

    Operation         Symbol                       Description                         Example

                      Addition              +        Adds one operand to the other                         a+b= 40

                      Subtraction            -       Subtracts second operand from the first               a-b= 20

                      Multiplication        *        Multiplies one operand by the second                 a*b=  300

                      Division              /        Divides first operand by the second                    b/a= 3

                      Modulus               %        Divides the first operand by the second,              b%a= 0
                                                     and returns the remainder

                      Increment             ++       Increases the integer value by 1                      a++ = 11

                      Decrement             --       Decreases the integer value by 1                      b-- = 29

                     Assignment operators

                     An assignment operator assigns a new value to a variable.
                     In the table given below, we are taking, value of variable a=10, and b=30.

                             Operator             Symbol              Description                     Example

                      Simple assignment              =       Assigns  value to the left  c = a + b (c = 10 + 30)
                      operator                               operand  from right operand       will assign the value of
                                                                                               c to a + b (c = 40)

                      Add AND assignment             +=      Adds  the  right  operand  to  b + = a (b + = 10) is
                      operator                               the left operand and assign  equivalent to b = b + a

                                                             the result to the left operand (b = 30 + 10) (b = 40)
                      Subtract AND                   -=      Subtracts the right operand  b – = a (b– = 10) is
                      assignment operator                    from the left operand and  equivalent to b = b – a

                                                             assigns the result to the left  (b=30-10) (b=20)
                                                             operand

                      Multiply AND                   *=      Multiplies the right operand  b *= a (b *= 10) is
                      assignment operator                    with  the left operand and  equivalent to b = b * a
                                                             assigns the result to the left  (b = 30 * 10) (b=300)
                                                             operand

                      Divide AND assignment          /=      Divides  the  left  operand  b /= a (b/ = 10) is
                      operator                               with  the  right  operand  and  equivalent to b = b / a

                                                             assigns the result to the left  (b = 30/10) (b=3)
                                                             operand.

                                                                                           Variables Using Block Coding  87

| 84 85 86 87 88 89 90 91 92 93 94 |