“The name of an array can be used as a pointer to the first element in the array”
a+i := &a[i]*(a+i) := a[i]int *p;
int j = 5;
int a[] = {0,1,2,3,4,5,6,7}
p = &a[2];
/* p + 3 will point to a[5] */
p += 4;
/* p points to a[6] */
printf("*p is %d", *p); /* should be a[6] == 6 */This is similar to adding an integer.
int *p;
int j = 5;
int a[] = {/* populate */}
p = &a[12];
/* p - 3 will point to a[9] */
p -= 4;
/* p points to a[8] */&a[N] even though it cannot be
dereferenced. The address exists but the value doesn’t*p++ or combining *
and ++ operators*p++ := *(p++)
:= Value of *p before increment; increment
p later(*p)++ := Value of *p before
increment; increment *p later*++p := *(++p)
:= Increment p first; Value of *p
after increment++*p := ++(*p)
:= Increment *p first; Value of
*p after incrementUse cases for this is creating a stack function, see c_programming_a_modern_approach
int a[20];
/* ... */
while (*a != 0)
a++; /* wrong as you are trying to make the array point somewhere else*/
p = a;
while (*p != 0)
p++; /* correct */