kaveer
8/29/2016 - 5:57 AM

Compound assignment operators

Compound assignment operators

answer += 42;

// Example 2

Don’t write this                     Write this

variable = variable * number;       variable *= number;
variable = variable / number;       variable /= number;
variable = variable % number;       variable %= number;
variable = variable + number;       variable += number;
variable = variable - number;       variable -= number;