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++.
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.
deleted by creator
i++
is a simple statement increasing the value ofi
by one. The statement from the picture does the same thing, the code is just really obfuscated. The boolean valuefalse
is usually represented as zero,true
as one. Therefore, we havefalse
, negation operator!
makes ittrue
. When we apply the minus operator, the programming language implicitly convertstrue
to1
. 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 ini
, let’s say41
, we take the value and subtract-1
, making it41-(-1)
, get42
and return the result toi
. Here you have your increment ofi
,i++
.Worth mentioning that this is C (or possibly C++).
could be javascript
or matlab
or julia
Lucky me, I’m not familiar enough with any of these languages.
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.booleans are implemented as having int values of 0 and 1, so kinda?
deleted by creator
Where exactly? Do you mean
i = i + 1;
? Yes, that would be the same statement – producing the same result. You could also usei += 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.The monstrosity in the image evaluates to
i++
which increments the variablei
by one.