C provides even shorter shorthand (shortest shorthand?) operators that make the code even smaller and clearer. These are the autoincrement and autodecrement operators.
Writing the counter = counter + 1;statement is equivalent to a shorter version, counter += 1;, as we have already learned. However, this simple expression happens so often, especially when incrementing or decrementing a counter or index, that there is an even shorter shorthand way to do it. For this, there is the unary increment operator of counter++; or ++counter;.
In each case, the result of the statement is that the value of the counter has been incremented by one.
Here are the unary operators:
- ++ autoincrement by 1, prefix or postfix
- -- autodecrement by 1, prefix or postfix