increments and decrements

i still don't understand how the pre and post works. it's a little confusing for me...
I am assuming by pre and post you mean putting them before and after then variable. Putting it before it like this:

1
2
3
int a = 1;
int b = 2;
a = ++b;


Will make the compiler increment b first, then assign b to a, making both values 3, whereas:

1
2
3
int a = 1;
int b = 2;
a = b++;


Will first assign b to a (making a 2) and then increment b, making b = 3.

The preincrement will increase the value then the compiler will use the new value. The postincrement will increase the value after the variable have been used.
EX:

a=0;
a++;
the computer will use the a=0 value then make a=1
If u put a=0;
++a;
the computer will increment a to 1 then use the value (directly 1)
Topic archived. No new replies allowed.