Skip to content
DevMeme
6778 of 7435
Why Does Everyone Keep Telling Me to Use C++ -- The Increment Operator Confusion
Languages Post #7432, on Nov 18, 2025 in TG

Why Does Everyone Keep Telling Me to Use C++ -- The Increment Operator Confusion

Description

A screenshot from Reddit's r/programminghorror subreddit showing a post titled 'Why does everyone keep telling me to use c++?' submitted by user ZERICO2005. The post describes a task to create a C function that finds the rightmost 0 in an integer, flips it to 1, and flips all 1's to its right to 0's. The code shows a uint32_t function using bitwise operations (AND, OR, NOT, left shift, right shift) with detailed comments. The function uses bit manipulation with operators like &, |=, ~, <<=, and >>=. The punchline at the bottom reads: 'Why are people so adamant that I use c++ instead of C?' -- the joke being that people are telling the author to 'use C++' meaning the language, but the author's C code already heavily uses the ++ increment operator, making them oblivious to the pun

Comments

39
Anonymous ★ Top Pick The real horror isn't the code -- it's that this person wrote a perfectly correct bit manipulation function in C and still can't figure out why everyone keeps recommending the language named after the operator they're already using on every line
  1. Anonymous ★ Top Pick

    The real horror isn't the code -- it's that this person wrote a perfectly correct bit manipulation function in C and still can't figure out why everyone keeps recommending the language named after the operator they're already using on every line

  2. Anonymous

    This code is a great interview question to see if a candidate will write 20 lines of buggy code or just give you `x | (x + 1)` and go to lunch

  3. @beton_kruglosu_totchno 7mo

    i get it but the joke is built on false premise return c+1 is not the solution to the original problem neither can the "flipping" be done by just adding something to the c

    1. @sylfn 7mo

      not a "false premise" that's how incrementing in base-2 works --- a chunk of least significant ones is flipped to zeroes and the next bit (the first zero) is flipped to one (if "right-most" means "least significant", and 1's and 0's are assumed to be the bits of input)

      1. @beton_kruglosu_totchno 7mo

        damn I misread this I read it as "to the left"

      2. @deadgnom32 7mo

        but what about endians?

        1. @purplesyringa 7mo

          endianness applies to bytes within integers, there are zero mentions of bytes anywhere, make your own conclusions

          1. @deadgnom32 7mo

            how then would a +1 flip digits?

            1. @purplesyringa 7mo

              math is cool like that

              1. @purplesyringa 7mo

                hint: 149375933999999999 + 1 = 149375934000000000, now apply the same thing to binary

                1. @ZgGPuo8dZef58K6hxxGVj3Z2 7mo

                  JavaScript would disagree with you

                  1. @ZgGPuo8dZef58K6hxxGVj3Z2 7mo

                    Wait nvm ccording to JavaScript 149375933999999999 is already 149375934000000000

                2. @deadgnom32 7mo

                  no

                3. @deadgnom32 7mo

                  you are flipping 99's not 1's

                  1. @sylfn 7mo

                    because it's base 10 and not base 2

                  2. @purplesyringa 7mo

                    hint: mayhaps the digit 9 might be magical because we're working in base 10

                4. @deadgnom32 7mo

                  if your LSB is on the different side — then +1 will flip from the other side but the task clearly defines left and right. not LSB and MSB

                  1. @purplesyringa 7mo

                    "left" always means "MSB" and "right" always means "LSB" because that's how we humans represent integers, hope this helps

                    1. @deadgnom32 7mo

                      not

                    2. @ZgGPuo8dZef58K6hxxGVj3Z2 7mo

                      That's arabic numbers. (Not the system arabs actually use)

                      1. @purplesyringa 7mo

                        true

                        1. @ZgGPuo8dZef58K6hxxGVj3Z2 7mo

                          Roman numbers are even weirder there they relative position can invert its value

                    3. @deadgnom32 7mo

                      shit. I may have some memory bug if you are all don't agree

                      1. @deadgnom32 7mo

                        @Capstra, 🖕

                    4. @chupasaurus 7mo

                      Roman numerals: exist

          2. @deadgnom32 7mo

            if you have a different order of bytes — then corresponding bits are reordered with them together

            1. @purplesyringa 7mo

              that's not how it works

        2. @Agent1378 7mo

          Big endian is dying or dead

        3. @ZgGPuo8dZef58K6hxxGVj3Z2 7mo

          It doesn’t matter

        4. @ZgGPuo8dZef58K6hxxGVj3Z2 7mo

          Does bitshift expose endianness? No. Does math expose it? No. Does most and oeast significant bit depend on big or little endian numbers? No. Then why should it matter here? Little endianness is only relevant when not working with whole numbers. A.K.A. streaming or storing them in a non uniform register/slot/buffer.

  4. @VanuxaKR 7mo

    std::uint32_t func(std::uint32_t c) { if (c == -1u) return 0; auto idx = std::countr_zero(~c); auto mask = idx == 0 ? -1u : (1u << (idx + 1u)) - 1u; return c ^ mask; } 🤡 <- it's me

  5. @imfreetodowhatever 7mo

    A programming meme on my vibecoding channel?? You expect me to comprehend actual C??

    1. dev_meme 7mo

      This made laugh, thanks ❤️

    2. dev_meme 7mo

      You just need vibe understanding 🙌

  6. @ZgGPuo8dZef58K6hxxGVj3Z2 7mo

    Why the fuck you need that much code for this?

    1. @ZgGPuo8dZef58K6hxxGVj3Z2 7mo

      I am pretty sure you can solve it with one single while/for loop and a bool

      1. @q_rsqrt 7mo

        you solve this with c++

      2. dev_meme 7mo

        the meme is that all what you need is c++ 🌚

  7. @ajnart 7mo

    Not understanding this made me feel like shit. Should’ve outsourced my brain to ChatGPT

Use J and K for navigation