Difference between array[i] and i[array] Expressions

Question: Are Expressions arrays[i] and i[arrays] same?

Answer: We know that we can use pointer and indirection to access an array. Let’s try to rewrite the exp.

    arrays[i];

using pointer as:

    *(arrays + i);

which, of course, we can write as:

advertisement
advertisement
    *(i + arrays); /* addition is 'commutative' */

which we rewrite in subscript form as:

        i[arrays];

So, these two expressions are same! But writing this way is awkward and one should practice decent style of programming!

Sanfoundry Global Education & Learning Series – 1000 C Tutorials.

Note: Join free Sanfoundry classes at Telegram or Youtube
If you wish to look at all C Tutorials, go to C Tutorials.

If you find any mistake above, kindly email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.