Well, not all languages allow for fun programming :)
I am passionate about connecting innovation with freedom, envisioning a future where technology uplifts everyone. Dedicated to coding and software development, my goal is to create meaningful advancements that enhance our liberties.
Well, not all languages allow for fun programming :)
In C you can group expressions within (
and )
separated with ,
. Expressions are evaluated in order and the last expression in the group is the returned value of the group.
If you’re hell bend on achieving the goodness of i++
equivalent you could wrap it up like this:
(i-=-1,i-1)
We’re talking C here of course.
Isn’t the evaluated value different from the expression? i++
returns the value of i before increasing. i-=-1
would return the value after it has been increased. Wouldn’t it be more correct to make it equal to ++i
Yes, yes, and someone else’s problem will be your problem after the job hop! :)
It works the same because the value of the last expression in the
for
loop is not used for anything. It’s the side effect of that statement that counts. Eg, the value ofi
is checked the next time the for loop is executed by the condition check. Try replacingi
in the condition check instead withi++
or++i
and you would see different results.Something like:
for (int i = 0; ++i < 10;) { ... }