其实,数组指针就是指针,指针数组就是数组,里面存了一堆地址,
#include <stdio.h> int main() { //定义指针数组 int a = 1,b = 2, c = 3; int *pa = &a; int *pb = &b; int *pc = &c; int *arr[3] = {pa,pb,pc}; for (int i = 0; i < 3; i++) { printf("*arr[%d] = %p\n",i, &arr); } //定义数组指针 int arr1[3] = {1,2,3}; int (*p)[3] = &arr1; *p[0] = 4; for (int i = 0; i < 3; i++) { printf("*arr1[%d] = %d\n",i, arr1); } //定义数组元素指针 int arr2[3] = {1,2,3}; int *parr20 = &arr2[0]; int *parr21 = &arr2[1]; int *parr22 = &arr2[2]; *parr20 = 5; *parr21 = 5; *parr22 = 5; for (int i = 0; i < 3; i++) { printf("*arr2[%d] = %d\n",i, arr2); } return 0; }
|