我用FORTRAN编程,但我决定学习C和C.我从C语言开始,我从未使用的一件事是指针,因为FORTRAN通过引用传递值.我构建了下面的示例代码,以了解指针如何与多维数组一起使用:
#include
#include
#define DIM1 3
#define DIM2 2
#define DIM3 4
void display3DArray1(int, int , int n, int (*arr)[][n]);
void display3DArray2(int rows, int cols1, int cols2,int arr[][cols1][cols2]);
int main(void)
{
int matrix3D[DIM1][DIM2][DIM3] = {
{ {1, 2, 3, 4}, {5, 6, 7, 8}},
{ {9, 10, 11, 12}, {13, 14, 15, 16}},
{ {17, 18, 19, 20}, {21, 22, 23, 24}}
};
int (*pmatrix3D)[DIM2][DIM3] = matrix3D;
display3DArray1(DIM1, DIM2, DIM3,pmatrix3D);
display3DArray2(DIM1, DIM2, DIM3,pmatrix3D);
return 0;
}
void display3DArray1(int rows, int cols1, int cols2,int (*arr)[][cols2]) {
printf("\n");
for(int i=0