1. About the first address of the array:
# Include <stdio. h> int main (void) {char CS [2] [3] ={{ 'A', 'B', 'C'}, {'D ', 'E', 'F' }}; char * P1, * P2, * P3, * P4; P1 = P2 = P3 = P4 = NULL; /* the following four pointers all point to the same address */P1 = & CS [0] [0];/* this is best understood */P2 = & CS [0]; p3 = & Cs; P4 = cs;/* this is the most convenient */printf ("% P \ n", P1, p2, P3, P4);/* display address */printf ("\ n % C \ n", * P1, * P2, * P3, * P4);/* display content */getchar (); Return 0 ;}
2. Address of other elements in the array:
In this example, the elements of the array should be arranged in the memory as follows:
[0] [0] [0] [1] [0] [2] [1] [0] [1] [1] [1] [2]
The following is the third element of the array obtained through a pointer:
# Include <stdio. h> int main (void) {int Nums [2] [3] ={{ 11, 12, 13}, {21, 22, 23 }}; int * P1, * P2; P1 = P2 = NULL; P1 = & Nums [0] [2]; P2 = Nums; P2 = P2 + 2; // P2 = (int *) nums + 2;/* or use this sentence to replace the above two rows */printf ("% d, % d \ n", * P1, * P2); getchar (); return 0 ;}
3. Common Methods for Traversing Arrays:
# Include <stdio. h> int main (void) {int Nums [2] [3] ={{ 11, 12, 13}, {21, 22, 23 }}; int I, J; for (I = 0; I
4. traverse the array by pointer:
# Include <stdio. h> int main (void) {int Nums [2] [3] = {11, 12, 13}, {21, 22, 23 }}; int * P = Nums; int I; for (I = 0; I
# Include <stdio. h> int main (void) {char CS [2] [3] ={{ 'A', 'B', 'C'}, {'D ', 'E', 'F' }}; char * P = cs; unsigned I; for (I = 0; I
# Include <stdio. h> int main (void) {char CS [2] [3] ={{ 'A', 'B', 'C'}, {'D ', 'E', 'F' }}; int I; for (I = 0; I
5. Explore the pointer address of the array again:
# Include <stdio. h> int main (void) {char CS [2] [3] ={{ 'A', 'B', 'C'}, {'D ', 'E', 'F'}; // in this example (two-dimensional array) // CS is the address pointing to the array CS [0] // * cs is the address pointing to CS [0] [0] printf ("% P, % P \ n ", CS, * cs); // ** CS points to the value of printf ("% C, % C \ n", ** CS, CS [0] [0]); getchar (); Return 0 ;}
6. Use pointers to traverse 3D Arrays:
# Include <stdio. h> int main (void) {char CS [2] [2] [3] ={{ 'A', 'B', 'C '}, {'D', 'E', 'F' }},{ {'1', '2', '3'}, {'4', '5 ', '6' }}; int I; int COUNT = sizeof CS/sizeof CS [0] [0] [0]; for (I = 0; I
7. It is easier to understand how to traverse multi-dimensional arrays or Use Pointer variables:
# Include <stdio. h> int main (void) {char CS [2] [2] [3] ={{ 'A', 'B', 'C '}, {'D', 'E', 'F' }},{ {'1', '2', '3'}, {'4', '5 ', '6' }}; char * P = (char *) Cs;/* compared to the above example, type conversion is added here; in this way, the compiler does not prompt */int I; int COUNT = sizeof CS/sizeof CS [0] [0] [0]; for (I = 0; I