C++ operator[] magic [duplicate]

  • A+
Category:Languages

This question already has an answer here:

I met a strange way of the appeal to an element of the array and thought it`s a mistake but it works. Can you explain how it works?

#include <iostream> int main() {   int a[] = {1,2,3,4};   std::cout << 1[a]; } 

 


BaseAddr[ Offset ] = *( BaseAddr + Offset ) Offset[ BaseAddr ] = *( Offset + BaseAddr ) = *( BaseAddr + Offset ) 

Comment

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: