What is the difference between int ++ and ++ int?
Possible duplicate:
What is the difference between ++ me and me ++
pre Decrement and post Decrement
Yes, I'm a nob, but I completely forgot what they both do.
I know, however, that int ++ just adds the value to the int.
So what is ++ int?
Thank.
source to share
If you are talking about C (or C) languages, it is exactly the same if you don't use value:
int a = 10;
int b = a++;
In this case, a
it becomes 11, and b
- 10. This post-increment - you increase it after use.
If you change this line above to:
int b = ++a;
it a
still becomes 11, but also b
. This is because it pre-magnifies - you magnify before use.
Note that this is not exactly the same for C ++ classes, there is efficiency to be gained by preferring one over the other. But since you're talking about integers, C ++ acts the same way as C.
source to share
Every expression in C or C ++ has a type, value, and possible side effects.
int i;
++i;
Type ++i
- int
. An increase is a side effect i
. The expression value is the new value i
.
int i;
i++;
The type i++
is int
. An increase is a side effect i
. The expression value is the old value i
.
source to share