C examples for Operator:Increment Decrement Operator
To increment or decrement a variable by one, use the increment (++) and decrement (--) operators.
x++; /* x = x+1; */ x--; /* x = x-1; */
Both of these can be used either before or after a variable.
x++; /* post-increment */ x--; /* post-decrement */ ++x; /* pre-increment */ --x; /* pre-decrement */
The post-operator returns the original value before it changes the variable.
The pre-operator changes the variable first and then returns the value.
#include <stdio.h> int main(void) { int x, y;//w w w . j a v a 2 s. c o m x = 5; y = x++; /* y=5, x=6 */ x = 5; y = ++x; /* y=6, x=6 */ }