++ Operator
Increment ++ and Decrement – Operator as Prefix and Postfix¶
In programming (Java, C, C++, JavaScript etc.), the increment operator ++ increases the value of a variable by 1. Similarly, the decrement operator -- decreases the value of a variable by 1.
Simple enough till now. However, there is an important difference when these two operators are used as a prefix and a postfix.
++ and – operator as prefix and postfix¶
- If you use the
++operator as a prefix like:++var, the value of var is incremented by 1; then it returns the value. - If you use the
++operator as a postfix like:var++, the original value of var is returned first; then var is incremented by 1.
The -- operator works in a similar way to the ++ operator except -- decreases the value by 1.
Let’s see the use of ++ as prefixes and postfixes in C, C++, Java and JavaScript.
Example:¶
#include <stdio.h>
int main() {
int var1 = 5, var2 = 5;
// 5 is displayed
// Then, var1 is increased to 6.
printf("%d\n", var1++);
// var2 is increased to 6
// Then, it is displayed.
printf("%d\n", ++var2);
return 0;
}
Last update :
May 1, 2026
Created : May 1, 2026
Created : May 1, 2026