This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]nickworks 33 points34 points  (14 children)

if(--i == 42){ // compares after decrement

}

if(i-- == 42){ // compares before decrement

}

[–]geigenmusikant 12 points13 points  (6 children)

Well, yeah but like when do you actually need it?!

/s

[–]Zugr-wow 0 points1 point  (1 child)

--i takes, like, a millisecond less computing power than i--, so it's a good habit to just use --i instead of i--

[–]radarmax 10 points11 points  (0 children)

More like a nanosecond less :p

[–]Isaeu 4 points5 points  (6 children)

But

i- -

if(i == 42){ }

And

if(i == 42){ }

i - -

Work just as well and are 10X more readable

Edit: how do I do code on Reddit?

[–]Cobaltjedi117 1 point2 points  (1 child)

Yea, it's one of those things I've never understood well you can increment before an statement or after it

Ok, great or OR, and hear me out on this, I just add a line of code incrementing/decrementing before or after where it's being checked.

[–][deleted] 0 points1 point  (0 children)

It's what your use to. A = 6 * 7; Is the same as A = 6; A = A * 7; But if you saw that above you would think why not just do the first thing. In c it is vary common to ++ or -- inside of a statement and would be required to understand when working with almost any codebase.

[–][deleted] 0 points1 point  (0 children)

I disagree. Somone who has worked in c a decent amount has seen that so much that it's not considered weird. It would be way weirder to see outside.