What is the difference between
Can you please give me an example and tell me how each produces a different output?
These operators are referred to as postfix and prefix operators, respectively. There are many such operators, and these in particular are the increment prefix and postfix operators.
A prefix operator executes before the rest of the code on the line. When using a prefix operator, whatever operation it causes will execute immediately when the line is run, then the rest of the code on the line will execute. The prefix operator directly changes the variable it operates on, so the rest of the line will use the modified version of the variable.
The postfix operator executes after the rest of the code on the line. When using a postfix operator, all of the code on the line will execute, then the operation caused by the postfix operator will be executed. The postfix operator directly changes the variable it operates on, as well.
Take the following code as an example:
int i = 5; // line 1
int j = ++i * 2; // line 2
int k = i-- * 2; // line 3
The final value for i in the above code is 5. The values for j and k are both 12. In line 2, the variable i is incremented before anything else on the line occurs. An equivalent to line 2 would be:
i = i + 1;
int j = i * 2;
In line 3, the variable i is decremented after everything else on the line occurs. An equivalent to line 3 would be:
int k = i * 2;
i = i - 1;
So you can see that during the execution of the code, the value of i changes twice, once for each of the postfix and prefix operators. The j and k variables end up being the same, even though, at a quick glance, you might not expect them to. The reason they are the same is due to when the change in i occurs -- before the multiplication in line 2 and after the multiplication in line 3.
If you're an optimization geek, it's useful to know that the prefix operator is usually faster than the postfix operator, so in cases where it doesn't matter which one you use (such as inside your typical for loop), it's best to go with the prefix operator. I can go into why the prefix operator is faster, if you like, but it's good enough just to know that it is slightly faster than the postfix operator.
If you have any questions about anything I've written, or if I did not fully answer your question, or even if you just have other questions, feel free to let me know!