Possible Duplicate:
Incrementing in C++ - When to use x++ or ++x?
I've seen things like i++ commonly used in, say, for loops. But when people use -- instead of ++, for some reason some tend to write --i as opposed to i--.
Last time I checked, they both work (at least in JavaScript). Can someone tell me if this is so in other C-family languages, and if it is, why do some people prefer --i to i--?
++i is faster than i++. Why? See the simple explication.
i++ will increment the value of i, but return the pre-incremented value.
temp = ii is incrementedtemp is returnedExample:
i = 1;
j = i++;
(i is 2, j is 1)
++i will increment the value of i, and then return the incremented value.
Example:
i = 1;
j = ++i;
(i is 2, j is 2)
This is simillar for --i and i--.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With