When should I use pre decrement and when to use post decrement?
and for the following code snippet, should I use pre or post decrement.
static privat
you should have ++i;
(not that it matters), and should have tempCounter--
Otherwise you will miss the "first" index of charArr
You use pre-decrement if you want to decrement the variable before the value is passed on to the remaining expression. On the other hand, a post-decrement evaluates the expression before the variable is decremented:
int i = 100, x;
x = --i; // both are 99
and
int i = 100, x;
x = i--; // x = 100, i = 99
The same obviously is true for increments.