Increment and Decrement Operators

 

Like C/C++, SPL provides two unusual operators for incrementing and decrementing variables. The increment operator ++ adds 1 to its operand; the decrement operator subtracts 1. Both ++ and may be used either as prefix operators (before the variable: ++n), or postfix (after the variable: n++). The expression ++n increments n before using its value, while n++ increments n after its value has been used. For example, if n is 5, then

 

x = n++;

 

sets x to 5, but

 

x = ++n;

 

sets x to 6. In both cases, n becomes 6.