1. No need to get the address of the array, because the array name itself is an address
# Include <stdio. h> int main (void) {char c = 'a'; char CS [] = "ABC"; printf ("% C, % s \ n", C, CS);/* Get the character and character array content */printf ("% P, % P, % P \ n", & C, Cs, & CS ); /* get the address of the character and character array. CS is no different from & CS */getchar (); Return 0 ;}
2. The address of the array element is continuous:
# Include <stdio. h> int main (void) {char CS [] = "ABC"; printf ("% P \ n", Cs, & CS [0], & CS [1], & CS [2]); getchar (); Return 0 ;}
3. The address represented by the array name is the address of the first element:
# Include <stdio. h> int main (void) {char STR [] = "ABC"; char * P1 = STR; char * P2 = & STR [0]; printf ("% P, % P \ n ", P1, P2); getchar (); Return 0 ;}
4. Access array elements through pointers:
# Include <stdio. h> int main (void) {char STR [] = "ABC"; char * P = STR; printf ("% C \ n", * P ); printf ("% C \ n", * p + 1); printf ("% C \ n", * P + 2); printf ("\ n "); printf ("% C \ n", * P); printf ("% C \ n", * ++ P); printf ("% C \ n ", * ++ P); getchar (); Return 0 ;}
5. traverse the array by pointer:
# Include <stdio. h> int main (void) {char STR [] = "123456789"; char * P = STR; int I; for (I = 0; I
# Include <stdio. h> int main (void) {char STR [] = "123456789"; char * P = STR; while (* P! = '\ 0') {printf ("% C \ n", * P); P ++;} getchar (); Return 0 ;}
# Include <stdio. h> # include <string. h> int main (void) {char STR [] = "123456789"; char * P = STR; int I; for (I = 0; I
# Include <stdio. h> int main (void) {int Nums [] = {111,222,333,444}; int * P = Nums; int I; for (I = 0; I
6. Note: pointer + 1 is to move a position based on the element size.
# Include <stdio. h> int main (void) {int Nums [] ={ 111,222,333,444}; int * P = Nums; int I; printf ("% d \ n", * P ); printf ("% d \ n", * (p + 1); printf ("% d \ n", * p + 1);/* this is not the case; this indicates that after the value is set, + 1 */getchar (); Return 0 ;}
7. the pointer above is actually a pointer to an array element. How can we declare a real array pointer?
# Include <stdio. h> int main (void) {int Nums [4] = {111,222,333,444}; int (* P) [4] = & Nums; /* Note the parentheses */printf ("% d \ n", (* P) [1]). /* it is not convenient to use */printf ("% d \ n", (* P) [2]); getchar (); Return 0 ;}