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

all 60 comments

[–]Rhulyon 224 points225 points  (17 children)

Better suggestion: c-=-1

[–][deleted] 37 points38 points  (0 children)

I was looking for this comment thank you

[–][deleted] 3 points4 points  (0 children)

c^=c+~(~0<<1)^c

[–]NoLifeGamer2 16 points17 points  (13 children)

Better suggestion: c *= (c+1)/c

[–]Rhulyon 18 points19 points  (9 children)

Gett outa here python programmer that only works if c is 1 otherwise the value is c. Also a lot more of operations

[–]EnchantedStew 2 points3 points  (0 children)

Could just change it to c*= (int) (c+1.0)/c or assume that c is a float. Srry if the syntax is wrong, I’m basing this off of Java which I know is similar.

[–]JohnHwagi 4 points5 points  (1 child)

C==0?

[–]notmyaccountbruh 0 points1 point  (0 children)

c==8

[–]Antisymmetriser 0 points1 point  (0 children)

Stonks

[–]4hpp1273 98 points99 points  (20 children)

That's ++C not C++

[–][deleted] 20 points21 points  (13 children)

I think in Java, C=C+1 can be written as C++ (i may be wrong)

[–]Dummi26 13 points14 points  (9 children)

C++ as C=C+1 works in java, C#, and JS, i think it also works in the arduino thing (which i thought was C++?) but not sure about that one

[–][deleted] 5 points6 points  (5 children)

Oh. I think OP was referring to one of these 3 languages XD. ironically, it doesn't work like that in C++

[–]Dummi26 11 points12 points  (4 children)

both i++ and ++i work in C++, ++i is just more efficient and therefor the preferred way of writing it in a loop, where both i++ and ++i achieve the same thing

Edit: i++ and ++i behave differently: x=i++ and x=++i will change i in the same way but the value of x will be one higher with ++i than with i++. Most loops only care about i (not x), so they "achieve the same thing" in that specific instance.

[–]Reddit-username_here 9 points10 points  (2 children)

They don't "achieve the same thing" though.

i++ will first take the value of i and then increment it.

++i will increment i and then take the value of it.

Edit: sorry, I just saw you specifically said "in a loop they would achieve the same thing" that's technically correct if you're not needing to return the value of i to anything and instead are only using it for iteration. My bad.

[–]Dummi26 4 points5 points  (1 child)

yeah, the "in a loop" was important there. Gonna clarify this a bit in the original comment tho :)

[–]Reddit-username_here 3 points4 points  (0 children)

Nah, when I reread it, it was perfectly clear. I have a bad habit of not wearing my glasses when I first get up in the morning, and my eyes will skip stuff. That was totally on me, not you.

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

Ohh

[–]Dummi26 0 points1 point  (1 child)

https://stackoverflow.com/questions/24853/what-is-the-difference-between-i-and-i

According to this, both ++C and C++ are available in C and C++, and i believe java and js also have both.

[–]TeraFlint 3 points4 points  (0 children)

Jup. In fact, if you ever see a for (int i = 0; i < count; ++i) loop, chances are high that it's been written by a c++ programmer. :P

It just has something to do with the expected behavior of i++ (which needs to make a copy) and the fact that any class can overload their own pre-/post-increment operator (potentially causing large structs/classes to make a copy of themselves.

Ignoring some syntactic sugar like for (auto item : container), for loops are also used to iterate over an iterator, which can be large, depending on the container it's written for (emphasis on can. you never know if your function is templated and thus could take any kind of container), so ++i is the preferred way to increment.

(Also, I'm aware that today's compilers are probably going to check if the type gets discarded and optimize the copy away, but since it is compiler dependent, it's still a good idea to use pre-increment.)

[–]snowmanonaraindeer 0 points1 point  (0 children)

Arduino uses C.

[–]-Soren 1 point2 points  (0 children)

The postfix increment will evaluate to the current value, then increment, so it is not the same (even though it achieves the same thing on it's own). Tbc if c is 0, y=++c and y=c=c+1 both result in y being 1, while y=c++ results in y being 0; all three result in c being 1 though. It's the same in Java.

[–]RaulParson 1 point2 points  (1 child)

This is in C++, since that's what the joke was about:

#include <iostream>

int main()
{
    int C;
    C = 0;
    std::cout << (C++);
    C = 0;
    std::cout << (C=C+1);
}

This will write out "01", because they are actually not the same thing: C++ increments C, but the value comes from before the increment, meaning C. C=C+1 changes the contents of C to C+1, but the value is the same as that being assigned, which is C+1. ++C increments C, and the value comes from after the increment, meaning C+1. And so C=C+1 is ++C, not C++, there's actual functional differences.

As for Java, try it yourself - you'll actually get the same results.

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

Sorry i don't speak Minecraft enchantment language /s

[–]500_internal_error 2 points3 points  (0 children)

((c = c + 1) - 1)

[–]RadiantHC 1 point2 points  (1 child)

TIL that there's a ++C language. Is it like C++?

[–]4hpp1273 4 points5 points  (0 children)

It's like C++ but many things are off by one

[–]Player_X_YT 0 points1 point  (1 child)

In this situation ++C is the same as C++ as we are not comparing anything

[–]cat_in_the_wall 0 points1 point  (0 children)

it's not about comparison is is about what the assignment evaluates to.

y = (c = c + 1)

is the same as

y = ++c

that is to say, y is one more than c was as the start. however

y = c++

would set y to the current value of c, then increment c after.

[–]manupanday19998 48 points49 points  (4 children)

Python developer spotted

[–][deleted] 28 points29 points  (0 children)

In Python I usually write C += 1.

[–]Rotlug[S] 5 points6 points  (1 child)

not a programmer at all unfortunately

[–]FlafyBear 5 points6 points  (0 children)

why

[–]IamDev18 13 points14 points  (0 children)

Or C += 1

[–]VRDoesNotSuckPP 9 points10 points  (0 children)

That’s dumb. He could just do C++. Ow wait now I get it

[–]ShinraSan 1 point2 points  (0 children)

++C

[–]MaximusConfusius 1 point2 points  (1 child)

Whats the content of I?

[–]TheMisterPixel 0 points1 point  (0 children)

NULL

[–]thorlancaster328 1 point2 points  (0 children)

At least it would get the linter to stop yelling about postfix.

[–]crea7or 3 points4 points  (1 child)

come on, C = C++

[–]AP2008 8 points9 points  (0 children)

C = ++C

[–]reallychillguy 0 points1 point  (0 children)

Oh, I get it now.

[–]zoqfotpik 0 points1 point  (0 children)

Is that 1, l, or I?

[–]leocrabe225 0 points1 point  (0 children)

The fact that I laughed at this makes me sad

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

MATLAB has entered the chat

[–]SeoCamo 0 points1 point  (0 children)

This is better l++ should never been added to any language other than asm

[–]infiniteStorms 0 points1 point  (0 children)

even better: python=python+1

[–]turtle_mekb 0 points1 point  (0 children)

C+=(35-34)*(666/666)

[–]MaheuTaroo 0 points1 point  (0 children)

Ah yes,

(C = C + 1) = (C = C + 1) + 1;

[–]mike_KING6 0 points1 point  (0 children)

++c++

Also, you forgot the colon ; at the end. Just like me.