Assignment Operators
- Assignment operators permit a more concise description of certain kinds of assignments.
- c = c + 3 (assign the value of c + 3 to c) can be written more naturally as c +=3 (increment c by 3).
| Assignment operator
| Sample expression
| Explanation |
+=
| c += 7 | c = c + 7 |
-=
| d -= 4 | d = d - 4 |
*=
| e *= 5 | e = e * 5 |
/=
| f /= 3 | f = f / 3 |
%=
| g %= 9 | g = g % 9 |
- Let c = 5.
- Question: Is c *= 3 + 7 equal to c = c * 3 + 7 or c = c * (3 + 7) ?
- How might you verify your answer?