Example 1 — Prefix versus postfix
The same variable gives different results depending on the form.
#include <stdio.h>
int main(void) {
int i = 5;
int a = i++;
printf("a=%d i=%d\n", a, i);
int b = ++i;
printf("b=%d i=%d\n", b, i);
int c = i--;
printf("c=%d i=%d\n", c, i);
int d = --i;
printf("d=%d i=%d\n", d, i);
return 0;
} How It Works
i++stores 5 ina, thenibecomes 6.++imakesi7 first, sobis 7.i--stores 7 inc, thenibecomes 6.--imakesi5 first, sodis 5.
