Computer Science 2211A/B Lecture Notes - Lecture 12: Array Data Structure
Document Summary
Pointers can point to array elements eg. int a[10], *p; p = &a[0]; *p = 5; // store 5 into a[0] If p points to an element of an array, the other elements can be accessed by performing pointer arithmetic. Adding an integer, subtracting an integer, and subtracting one pointer from another. If p points to the array element a[i], then p + j points to a[i+j] If p points to the array element a[i], then p - j points to a[i-j] When on pointer is subtracted from another, the result is the distance between the pointers. If p points to a[i] and q points to a[j], then p - q is equal to i - j. Performing arithmetic on a pointer that does not point to an array element. Subtracting pointers unless both point to elements of the same array. Pointers can be compared using the relational and equality operators.