Skip to content →

C a[i] vs i[a]

When following the MIT 6.828 open course, there’s one C source code discussing pointers in Exercise 4 of lab 1.

There’s one line of code in pointers.c:

3[a] = 302;

Looks weird at first sight; but TCPL says in Chapter 5.3:

In evaluating a[i], C converts it to *(a+i) immediately; the two forms are equivalent.

So: a[i] and i[a] are equvalent (if i is a constant). 🙂

Published in OS


    Leave a Reply

    Your email address will not be published. Required fields are marked *

    This site uses Akismet to reduce spam. Learn how your comment data is processed.