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 are pointing to the same address * *
P1 = &cs[0][0]; * * This best understanding * *
P2 = &cs[0];
P3 = &cs;
P4 = CS; * This is the most convenient * *
printf ("%p\n%p\n%p\n%p\n", p1, P2, p3, p4); /* Display Address * *
printf ("\n%c%c%c\n", *p1, *p2, *P3, *P4); /* Display Content * *
GetChar ();
return 0;
}
2. The address of other elements of the array:
In the example, the elements of an array should be arranged in memory in this way:
[0] [0] [0][1] [0][2] [1][0] [1][1] [1][2]
The following is the way to get the third element of an array by 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; /* 或者用这一句替换上面两行 */
printf("%d,%d\n",*p1,*p2);
getchar();
return 0;
}