Yes, you are right it is even lower level question, even assembler has []
operator. This answer said quite good but my explanation would be:
arr[x]
is the same as *((void *)(&arr) + x * sizeof(arr[0]))
It looks a bit complicated, but generated code is simple. It is because compiler knows sizeof(arr[0])
and it is hard-coded in compiled code, also (void *)(&arr)
is just language standart which protects programmer from dumb mistakes and in compiled code there is no type conversions.
One more thing, as I mentioned lower level languages, so need to mention higher. Using them you can overload operator and make it do whatever you want.