Go back to Richel Bilderbeek's homepage.
Go back to Richel Bilderbeek's C++ page.
operator++ (also called the increment operator) increases an integer's value by one. To decrease an integer's value by one, use operator--
operator++ has a pre-fix and post-fix form, which are '++i' and 'i++' respectively. The prefix form returns the value of i its new value, the postfix form returns the value of i before its increment. Prefer '++i' over 'i++' [1,2].
#include <cassert> |
There are four ways to increment a value by 1, that make use of different operators and some of temporary copies.
Code | Temporary copy yes/no |
i = i + 1; | yes |
i += 1; | no |
++i; | yes |
i++; | no |
struct MyInt |
Go back to Richel Bilderbeek's C++ page.
Go back to Richel Bilderbeek's homepage.