Home Segments Index Top Previous Next

313: Sidetrip

Although augmented assignment operators are not used in this book, there are situations in which an expression written with an augmented assignment operator is arguably better than the corresponding expression without the augmented assignment operator. In the hardcopy version of this book, for example, you learn about C++ arrays: in particular, you learn that you can reassign an array element to twice its former value as follows:

array name [index-producing expression]  
  = array name [index-producing expression] * 2 

Alternatively, using an augmented assignment operator, you can write the reassignment expression as follows:

array name [index-producing expression] *= 2 

Plainly, if the index-producing expression is complex, the augmented assignment operator offers one way to keep size down and to avoid a maintenance headache should the expression require modification.