Tuesday, September 24, 2019

C++ array[index] vs index[array]









Is the possibility of both array[index] and index[array] a compiler feature or a language feature. How is the second one possible?


Answer



The compiler will turn



index[array]


into




*(index + array)


With the normal syntax it would turn



array[index]


into




*(array + index)


and thus you see that both expressions evaluate to the same value. This holds for both C and C++.


No comments:

Post a Comment

hard drive - Leaving bad sectors in unformatted partition?

Laptop was acting really weird, and copy and seek times were really slow, so I decided to scan the hard drive surface. I have a couple hundr...