我想从函数引用中获取值。
我的职能是:
void print2D_A(double (*ary2D)[3][4]){ ... }
主要:
double ary2D[3][4] = {
{10.1, 11.2, 12.3, 13.4},
{20.1, 21.2, 22.3, 23.4},
{30.1, 31.2, 32.3, 33.4}
};
print2D_A(&ary2D);
获取函数的第一个值:
*(ary2D)+1
最佳答案
不要使用2D数组的地址,这确实不清楚。
void print2D_A(double ary2D[3][4]) // `ary2D` is already a pointer of array, seems like `douible* ary2D`
{
printf("%f\n", ary2D[0][0]);
}
编辑:
void print2D_B(double ary2D[3][4]) // `ary2D` is already a pointer of array, seems like `douible* ary2D`
{
for(int i=0; i<3; i++)
{
for(int j=0; j<4; j++)
{
printf("%f, ", ary2D[i][j]);
}
printf("\n");
}
}
int main(int argc, char *argv[])
{
double ary2D[3][4] = {
{ 10.1, 11.2, 12.3, 13.4 },
{ 20.1, 21.2, 22.3, 23.4 },
{ 30.1, 31.2, 32.3, 33.4 }
};
print2D_A(ary2D); // In fact, this is a pointer of double array
return 0;
}
关于c - 从指针数组获取值-按引用调用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/55139118/