My C programming notes

From Zheyong Fan
Revision as of 14:28, 26 February 2020 by Brucefan (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

I will re-read some C programming books and take some notes along with the reading.

  • A wired feature: a[3] is equivalent to 3[a]. Try this program:
#include <stdio.h>

int main()
    int a[4] = {0, 1, 2, 3};
    int y = 3[a];
    printf("3[a] = %d\n", 3[a]);
    return 0;

It's output is:

3[a] = 3

The reason is a[n] is interpreted as *(a + n). And because *(a + n) should be equivalent to *(n + a), the compiler (standard) also accept n[a].