• Adda
      link
      fedilink
      arrow-up
      7
      ·
      edit-2
      4 years ago

      i++ is a simple statement increasing the value of i by one. The statement from the picture does the same thing, the code is just really obfuscated. The boolean value false is usually represented as zero, true as one. Therefore, we have false, negation operator ! makes it true. When we apply the minus operator, the programming language implicitly converts true to 1. Adding minus, we get -1. Operator -= takes the value from the left operand and subtracts from it the value of the right operand. The result is stored to the left operand. Therefore, we have a value in i, let’s say 41, we take the value and subtract -1, making it 41-(-1), get 42 and return the result to i. Here you have your increment of i, i++.

      • nutomicA
        link
        fedilink
        arrow-up
        4
        ·
        4 years ago

        Worth mentioning that this is C (or possibly C++).

          • nutomicA
            link
            fedilink
            arrow-up
            1
            ·
            4 years ago

            Lucky me, I’m not familiar enough with any of these languages.

        • AgreeableLandscapeOPM
          link
          fedilink
          arrow-up
          1
          ·
          4 years ago

          Does C/C++ do automatic type casting? I feel like an operation on false shouldn’t be a valid input for an integer variable. At least I hope not.

          • mae
            link
            fedilink
            arrow-up
            2
            ·
            4 years ago

            booleans are implemented as having int values of 0 and 1, so kinda?

        • Adda
          link
          fedilink
          arrow-up
          1
          ·
          4 years ago

          Where exactly? Do you mean i = i + 1;? Yes, that would be the same statement – producing the same result. You could also use i += 1; so you spare one character you don’t have to type (i) – this is used in Python for example, because Python doesn’t use ++ operator for increment, it doesn’t know ++ operator in fact. But it turns out programmers are lazy and increment by one is so often used that some programming languages (such as C or C++) defines ++ operator as even a quicker way to increment by one.

    • AgreeableLandscapeOPM
      link
      fedilink
      arrow-up
      1
      ·
      4 years ago

      The monstrosity in the image evaluates to i++ which increments the variable i by one.