我需要获取一个指向二维数组的指针。如果有帮助,这些大小在编译时是已知的。我需要根据变量的传入值对某个数组执行操作。
//Global arrays
// int c[6000][1000];
// int a[6000][1000];
void fun(int x){
//Setup a pointer here
//Possible solution: int (*pointer)[6000][1000];
int **pointer;
if (x == 0){
pointer = c;
}
else{
pointer = a;
}
//Modify pointer here and have changes reflect back to the array it was based off of
pointer[0][17] = 42;
}
我已经查看了近十二篇关于如何执行此操作的不同堆栈溢出文章,但我找不到一种方法来获取指向二维数组的简单指针。
最佳答案
//Global arrays
int c[6000][1000];
int a[6000][1000];
void fun(int x) {
int (* ptr)[1000];
if (x == 0) {
ptr = c;
} else {
ptr = a;
}
ptr[0][17] = 42;
}
关于c - 获取指向二维数组的指针,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47045204/