C语言19 指针取值的两种方式

一级指针和多级指针

int i =100;
int* p1 = &i; 
int** p2 = &p1; 
int*** p3 = &p2; 
int**** p4 = &p3; 
int***** p5 = &p4 
int****** p6 = &p5; 
int******* p7 = &p6;
int****** px1 = *(p7);
int***** px2 = *(px1);
int**** px3 = *(px2);
int*** px4 = *(px3);
int** px5 = *(px4);
int* px6 = *(px5);
int px7 = *(px6);
int px7 = *(*(*(*(*(*(*(p7))))))); 

*()与[]的互换表示

int* p = (int*)1;
printf("%d %d \n",p[0],*p);  //p[0] = *(p+0) = *p 
int** p = (int**)1;
printf("%d %d \n",p[0][0],**p); 
printf("%d %d \n",p[1][2],*(*(p+1)+2));
int*** p = (int***)1;
printf("%d %d \n",p[1][2][3],*(*(*(p+1)+2)+3)); 
同理:
*(*(*(*(*(*(*(p7)))))))) 
= *(*(*(*(*(*(p7+0)+0)+0)+0)+0)+0)
= p7[0][0][0][0][0][0][0] 

总结

*(p+i) = p[i] 
*(*(p+i)+k) = p[i][k] 
*(*(*(p+i)+k)+m) = p[i][k][m] 
*(*(*(*(*(p+i)+k)+m)+w)+t) = p[i][k][m][w][t] 
*() 与 []可以相互转换 
updatedupdated2024-10-152024-10-15