#post vs pre inc/decr

7 messages · Page 1 of 1 (latest)

strange lynx
#

In what instance would post vs pre matter for increments?

bright compassBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

craggy junco
#

likely it's just about phrasing the same logic differently

light stratus
craggy junco
#

for example:

for(int i = N; --i;)

vs

for(int i = N - 1; i; i -= 1)

just about the same, but using pre-increment could ease things

open zealot
#

Basically a short hand for if you want to do

/* int y = ++x; */
x += 1
int y = x;

or

/* int y = x++; */
int y = x;
x += 1
dusk ruin
#

the difference is relevant if you do arr[x++] or arr[++x]
many people would say doing either of those is a bad idea and is bugprone, but that would be the most common example ime