If pa points to an element in the array, pa + 1 points to the next element, and pa + I points to the next element. Therefore, if pa points to a [0], * pa is actually a [0], * (pa + 1) is a [1], * (pa + I) is a [I]. Based on this idea, we can use pointers to access arrays.
# Include <stdio. h> int main (int argc, char * argv []) {int score [10] = {,}; int wait, length, I; length = sizeof (score)/sizeof (score [0]); for (I = 0; I <length; I ++) {printf ("% d \ n ", * (score + I);} scanf ("% d", & wait );}
Program output:
76859067597982959165
The array subscript is closely related to the pointer. After the execution of the statement pa = & a [0], the pa and a have the same value, and * pa = a [0]. In fact, the C language uses pointers to calculate the array downlink. Subscript is equivalent to pointer.
When an array name is passed to a function, the address of the first element of the array is actually passed. Therefore, the array name parameter must be a pointer.
Programs that calculate the string length can be written as follows:
Int strlen (char * s) {int n; for (n = 0; * s! = '\ 0'; s ++) n ++; return n ;}
S is a pointer, that is, a variable. It is valid to perform auto-increment on it.