i++
plus-square
image
21
image
@peppermint
5
edit-2
2M

i think this post is offensive

/s

@AgreeableLandscape
mod
admin
creator
32M

So do I.

thanks i hate it… 😂

10_0
32M

can someone explain the joke please?

Adda
6
edit-2
2M

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++.

@nutomic
admin
42M

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

@AgreeableLandscape
mod
admin
creator
12M

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
22M

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

shilangyu (lemmur)
2
edit-2
2M

could be javascript

or matlab

or julia

@nutomic
admin
12M

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

10_0
12M

why not just do i+1?

Adda
12M

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.

@AgreeableLandscape
mod
admin
creator
12M

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
  • 1 user / day
  • 1 user / week
  • 9 users / month
  • 83 users / 6 months
  • 1404 subscribers
  • 167 Posts
  • 273 Comments
  • Modlog