Course Content
Programming in C
About Lesson

++ is called the increment operator which increases the value of its operand by 1. -- is the decrement operator which decreases the value of its operand by 1. These operators can be used both as prefix (++n or --n) and suffix(n++ or n--). The expression ++n increments the value of n before it gets used, whereas n++ increments the value of n after it has been used.

In the following example code:

int n = 1;
int x = ++n;
int y = n++;

x is assigned the value of n after it has been incremented. So, x would be equal to 2 (same as n). In the next line, y would be assigned the current value of n, before it gets incremented, so y would be equal to 2 and n would then be incremented to 3.

Scroll to Top