- int main(int argc, const char * argv[]) {
- int arr[3][4] = {{1,2,3,4},
- {6,7,8,8},
- {5,4,2,2}
- };
- //二维数组指针行指针遍历二维数组
- int (*p)[4] = arr;
- for (int i = 0; i < 3; i++) {
- for (int j = 0; j < 4; j++) {
- printf("%d\t",*(*(p+i)+j));
- }
- printf("\n");
- }
-
- //用二维数组指针列指针遍历二维数组
- for (int i = 0; i < 3; i++) {
- for (int j = 0; j < 4; j++) {
- printf("%d\t",*((p[0]+j)+4*i));
- }
- printf("\n");
- }
- // 用一维指针数组遍历数组
- int *p1[3] = {arr[0],arr[1],arr[2]};
- for (int i = 0; i < 3; i++) {
- for (int j = 0; j < 4; j++) {
- printf("%d\t",*(*(p1+i)+j));
- }
- printf("\n");
- }
-
- return 0;
- }
复制代码 |
|