What IndexNum[ptr] actually is?

While participating in challanges, I encountered statements like 3[ptr] Wht they actually are, and what we call them, i unable to attach a screenshot, I can understand how this does work, but just want to grab some more details, i have no idea about what we call them so can't google, and mostly, I'm getting answer related to arrays and indexing, but nothing like this. The code is like .. int ptr[2][3]={1,2,3,4,5,6}; std::cout<<2[ptr[1]]<<std::endl; Every Answer will be helpful, thanks in advance!! https://code.sololearn.com/c64h20CyxTwm/?ref=app Edit: got some answer, as + is commulative these ptr operations are legal, they are nothing but a alternate way to write program, correct me if I'm wrong Ptr[x] = *(ptr+x) which is equal to *(x+ptr ) = x[ptr]

9/14/2019 6:02:34 AM

Satyam Mishra

2 Answers

New Answer


Ptr[x] = *(ptr + x) = *(x + ptr) = x[Ptr]. You forgot the dereference operator.


int ptr[2][3]={1,2,3,4,5,6}; cout<<2[ptr[1]]<<ptr[1][2]<<endl; From the above code you can see that - Array[1] =1[Array].