The short answer
In computing, an increment is a step up in a value, usually by one. Adding 1 to a counter is an increment. Its opposite is a decrement, which steps a value down, usually by one.
Where increments show up
Increments appear in many everyday programming tasks:
- Counters track how often something happens, such as clicks, errors, or items processed.
- Loop variables move through a sequence one step at a time.
- Indexes point to the next position in a list or array.
- Program counters in a processor usually move forward after each instruction.
- Identifiers are sometimes assigned by taking the last number and increasing it by one.
- Version numbers can go up by one for each small update, depending on the versioning scheme.
Increment and decrement
An increment raises a value, and a decrement lowers it. Both usually work in steps of one. In a loop, the loop variable may go up with each pass or down with each pass, depending on how the loop is written.
Increments in C++
In C++, you increase a variable with the c increment operator, written ++. Here is a small example:
#include <iostream>
int main() {
int visits = 0;
visits++; // one more visit
visits++; // two visits
std::cout << visits << "\n"; // prints 2
return 0;
}
The ++ symbol can go before or after a variable. Both forms add one, but they give back different values when used inside a larger expression.
Quick summary
- An increment raises a value, usually by one.
- Counters, loops, indexes, identifiers, and version numbers all rely on increments.
- In C++,
++increments a variable.