# What is the difference between ++i and i++?

After watching Precedence in the Week 1 Shorts, I know what `i++` means, but I still don't understand: What is the difference is between `i++` and `++i`?

`x++` - Post-increment operator
`++x` - Pre-increment operator

In short,
`x++` - `x` is incremented after the current statement is evaluated.
`++x` - `x` is incremented before the current statement is evaluated.

Huh?
Well, lets say we have a function called `foo` which has a local variable `x`:

``````int foo()
{
int x = 0;
return x++;
}
``````

In this function, `x` is initialized to `0` and `foo` returns `x++`.

At first you might think that the return value of `foo` will be 1, since `x = x + 1` (i.e. `x++`) is equal to 1.

However, recall that for `x++`, `x` is incremented after the current statement is evaluated. So the current value of `x` (0) is returned first, and then `x` is increment (in actual fact, since the statement is leaving the function, `x` disappears).

This is in contrast to `++x`, which updates the value of `x` first, before it's used in the current statement.

``````int y = x++; // x is zero in this statement until the next line, so y is 0