以下で共有している 3 次元配列のグループへのポインターを宣言しました。3 次元配列へのポインターを使用して 3 次元配列の要素にアクセスする際に問題があります。
#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 次元配列の要素にアクセスする方法です。私の場合、出力は私のコードが要素 90,100,9,11 にアクセスしていないことを示しており、上記のコードでこれにアクセスするにはどうすればよいでしょうか。前進。