English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The increment operator is used to increase the value by one, and decrement is the opposite of increment. The decrement operator decreases the value by one.
pre-incrementing (++ i) -Incrementing the value before assigning it to a variable1.
incrementing after (i ++) -After assigning a value to a variable, the value will increment.
The following is the syntax for incrementing before and after.
++variable_name; // Pre-increment variable_name++; // Post-increment
Here,
variable_name-any name given by the user to a variable.
This is C ++incrementing before and after.
#include <iostream> using namespace std; int main() { int i = 5; cout << "The pre-incremented value: " << i; while(++i < 10 ) cout << "\t" << i; cout << "\nThe post-incremented value: " << i; while(i++ < 15 ) cout << "\t" << i; return 0; }
Output Result
The pre-incremented value: 5 6 789 The post-incremented value: 10 1112131415