Assignment operators are operators, which are used to simplify the coding of certain type of assignment statement. The syntax is
variable operator = expression
where,
variable - valid user defined name
operator - + - * / %
expression - constant (s)or a variable(s) or operator(s)
Example
The table given below lists the operators with example.
Operator | Meaning |
+= | value of LHS variable will be added to the RHS value and is assigned to LHS variable. |
-= | RHS value will be subtracted from LHS variable and is assigned to LHS variable. |
*= | value of LHS variable will be multiplied by the RHS value and is assigned to LHS variable. |
/= | value of LHS variable will be divided by the RHS value and is assigned to LHS variable. |
%= | value of LHS variable will be divided by RHS value and the remainder will be stored in the LHS variable. |