next up previous contents
Next: Multi-dimensional arrays and nested Up: 4 Arrays, nested loops Previous: Array manipulation and references   Contents

Composite operators

As a short diversion from arrays, you will by now have been using the arithmetic operators +, -, *, / and % enough to appreciate the usefulness of the composite operators. These are +=, -=, *=, /= and %=, and their uses are:

x += y            // shorthand for x = x + y
x -= y            // shorthand for x = x - y
x *= y            // shorthand for x = x * y
x /= y            // shorthand for x = x / y
x %= y            // shorthand for x = x % y



RHUL Dept. of Physics