#include <stdio.h>

int
main()
{
  int arr[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
  int i = 3;
  printf("%d\n", i[arr]);
  return 0;
}

If you index an integer with an array in C, it gives you the same result as when you index an array with an integer. This is because array indexing is equivalent to pointer arithmetic. i’th member of arr equals to arr plus i equals to i plus arr equals to arr’th member of i.

  • Sivecano@lemmy.dbzer0.com
    link
    fedilink
    English
    arrow-up
    7
    ·
    10 days ago

    Subscript operator (in C) is just syntac sugar. i[0] fails because you’re dereferencing an integer not because the operator isn’t defined. (also, arrays are just pointers)