When the ++
operator appears after the variable, as in your example i++
, the increment of i, happens after the operation is over.
that's why the first print in the first example is zero, you haven't added yet, and then second one is 1.
the second example is the same as saving i, then incremeting it, and placing the original back.
i++
is an operator itself.
You could experiment the first one with ++i
which will increase i before doing the printing action