我已经声明了一个指向我在下面共享的一组 3-d 数组的指针。我在使用指向 3-d 数组的指针访问 3-d 数组的元素时遇到问题。
#include <stdio.h>
void main()
{
int m,row,col;
int *ptr,*j;
int array[2][5][2]={10,20,30,40,50,60,70,80,90,100,18,21,3,4,5,6,7,81,9,11};
int (*p)[5][2]; // pointer to an group of 3-d array
p=array;
for(m=0;m<2;m++)
{
ptr=p+m;
for(row=0;row<5;row++)
{
ptr=ptr+row;
for(col=0;col<2;col++)
{
printf("\n the vale is %d",*(ptr+col));
}
}
}
}
输出:
the value is 10
the value is 20
the value is 20
the value is 30
the value is 40
the value is 50
the value is 70
the value is 80
the value is 18
the value is 21
the value is 18
the value is 21
the value is 21
the value is 3
the value is 4
the value is 5
the value is 7
the value is 81
the value is -1074542408
the value is 134513849
我的问题是如何使用指向数组的指针访问 3-d 数组的元素,在我的情况下,输出显示我的代码没有访问元素 90,100,9,11 以及如何在上面的代码中访问它。谢谢进步。