Assignment Operators:
The operators which are used to assign a value (i.e., result
of an expression) to an operand are called Assignment Operators.
The following are assignment operators
Operator
|
example
|
Let x=7 and y=4
|
=
|
x = y
|
x=y=4
i.e., x=4
|
+=
|
x += y
| x= x + y i.e., x=7+4=11 |
-=
|
x -=y
|
x=x-y
i.e., x=7-4=3
|
*=
|
x*=y
|
x=x*y
i.e., x=7*4=28
|
/=
|
x/=y
|
x=x/y
i.e., x=7/4=1
(assume x and y are integers.)
|
%=
|
x%=y
|
x=x%y
i.e., x=7%4=3
|