Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
iamai20045yI wish there was a zoom-in on the face of the other guy while he was pouring in the coke. imagining it like 😱
-
@Lensflare no, wait. I guess that pointer + integer already takes into account the size of the the pointer type. So 2[a] should indeed work for any sizeof element.
-
@Lensflare In C++ the compiled code should be identical. This is for arrays and not more complex types that use operator[]()
-
@Demolishun yeah I just learned from stackoverflow that a[b] is translated to *(a + b)
the plus operator takes one integer and one pointer. Order of operands doesn't matter so we get classic pointer arithmetics.
The pointer is advanced by the integer value multiplied by the size of the pointer type.
These are the bits I had to understand in order to understand why a[b] is the same as b[a]
Related Rants
It’s not a bug, it’s a feature.
joke/meme
justdeveloperthings
meme
itsafeature
itsnotabug
bug
developer
joke
feature