#include <stdio.h>
int main(){
//一维指针数组
int a[]={1,2,3};
int *p[3]={&a[0],&a[1],&a[2]};
printf("*P=%p\n",p);//*p=0x7fff5ab20c2c
printf("*p+1=%p\n",p+1);//*p+1=0x7fff5ab20c30
printf("*(P+1)=%d\n",*(*(p+1)));//*(P+1)=2
printf("&p[0]=%p\n",&p[0]);//&p[0]=0x7fff5ab20c2c
printf("&a=%p\n",&a);//&a=0x7fff5ab20c2c
printf(" a=%p\n",a);// a=0x7fff5ab20c2c
for(int i=0;i<3;i++){
printf("a[%d]=%p\n",i,&a[i]);
//a[0]=0x7fff5ab20c2c a[1]=0x7fff5ab20c30 a[2]=0x7fff5ab20c34
//&a==a==a[0]==*p==&p[0] 都是数组的首地址
}
for(int i=0;i<3;i++){
printf("%d\n",*(a+i));
}
printf("------------------------二维指针数组-------------------------\n");
int arr[2][2]={
{1,2}, //------->arr[0]
{3,4} //------->arr[1]
};
int *p1[2]={arr[0],arr[1]};
printf("*p1=%p\n",p1);//*p1=0x7fff588d7bf0 指针数组的首地址
printf("*p1[0]=%p\n",p1[0]);//*p1[0]=0x7fff588d7c00
printf("p1+1=%d\n",*(*(p1+1)));//p1+1=3
printf("&arr[0]=%p\n",&arr[0]);//&arr[0]=0x7fff588d7c00
printf("p1+1=%p\n",p1+1);//p1+1=0x7fff588d7bf8
printf("arr=%p\n",arr);//arr=0x7fff588d7c00
printf("&arr[0][0]=%p\n",&arr[0][0]);//&arr[0][0]=0x7fff588d7c00
printf("&arr=%p\n",&arr);//&arr=0x7fff588d7c00
//p1[0]=&arr[0]=arr=&arr=&arr[0][0] 都是数组的首地址
for(int i=0;i<2;i++){
for(int j=0;j<2;j++){
// arr[0][0]=0x7fff588d7c00
// arr[0][1]=0x7fff588d7c04
// arr[1][0]=0x7fff588d7c08
// arr[1][1]=0x7fff588d7c0c
printf("arr[%d][%d]=%p\n",i,j,&arr[i][j]);
}
}
for(int i=0;i<2;i++){
for(int j=0;j<2;j++){
printf("%d\n",*(*(p1+i)+j));//==p1[i][0]+j=p1[i][j]
}
}
return 0;
} |
|