Tuesday 24 September 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

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...