prev

Pointers and Arrays

next

A one dimensional array is really just a pointer to a set of data.
      int a [5] = { 0, 1, 2, 3, 4 };
      int *ptr_a;
      int x;

      /* point pa to the first element of a */
      ptr_a = &a[0];            /* or just "ptr_a = a" */

      /* copy the value of a[0] into x */
      x = *ptr_a;
    
Since ptr_a points to a particular memory address then, by definition, (ptr_a + 1) will point to the next address and (ptr_a - 1) will point to the previous one.
      /* copy the value of a[1] into x */
      x = *(ptr_a + 1);
    
Therefore, *(ptr_a + i) is the same as a[i]

One difference between a pointer and an array name
      ptr_a = a;                /* legal */
      ptr_a++;                  /* legal */

      a = ptr_a;                /* not legal */
      a++;                      /* not legal */