Skip to main content

Section 13.5 Compound Assignment Operators

In programming we often update the values of variables using statements such as:
i = i + 1;fac = fac * i;num = num - 1;
These common coding tasks, where a certain operation (i.e. addition, subtraction, etc.) is being done to one variable itself (so the variable appears on both sides of the assignment operation), can be written in a shorthand using compound assignment operators.
In the first example above, we want to increment i by one, meaning we take the old value of i, add one to it, and store the new value back in i. However, we can achieve the same result using a compound assignment operator!
In the following video, we’ll learn about this shorthand notation for such variable updates.

If you cannot see this codecast, please click here.

Aside: Video Description.