i++
plus-square
image
20
image
@peppermint@lemmy.ml
4
edit-2
21d

i think this post is offensive

/s

So do I.

10_0
321d

can someone explain the joke please?

Adda
6
edit-2
21d

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 5, we take the value and subtract -1, making it 5-(-1), get 6 and return the result to i. Here you have your increment of i, i++.

10_0
114d

why not just do i+1?

Adda
114d

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.

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

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
213d

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

shilangyu (lemmur)
2
edit-2
19d

could be javascript

or matlab

or julia

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

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

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

  • Posts must be relevant to programming or programmers
  • No NSFW content. *Jokes must be in good taste. No hate speech, bigotry, etc.
  • 0 users online
  • 2 users / day
  • 10 users / week
  • 30 users / month
  • 83 users / 6 months
  • 13 subscribers
  • 93 Posts
  • 147 Comments
  • Modlog