C++ arr[i] and i[arr] are equivalent

Just discovered something interesting in C++ In C++: 👉 arr[i] and i[arr] are exactly the same. 𝗪𝗵𝘆? Because arr[i] is just pointer math: arr[i] == *(arr + i) i[arr] == *(i + arr) Since addition is commutative, both give the same result. 𝗧𝗮𝗸𝗲𝗮𝘄𝗮𝘆: You might never write i[arr] in real-world code, but understanding this gives you a deeper insight into how C++ actually works. #CPP #Programming

  • graphical user interface, text, application

two cents of advice, dont use c style arrays in c++ , there is a reason std::array<type, size> exists

Aur ek fun fact - yeh C mein bhi kaam karta hai, kyunki C++ ne yeh directly C se liya hai. Dennis Ritchie ke zamane se chal raha hai yeh kissa 😄

Bro unlocked pointer math after 53 years since C was released!!!

Wait a min....Let me just check it!

Like
Reply

Useless post. Who will use the other way? ONLY a buzz‼️‼️

No space between main() and { ? Barbaric

See more comments

To view or add a comment, sign in

Explore content categories