如何到达指针数组指向的数组?

时间:2021-06-24 17:11:38

标签: arrays pointers malloc

我正在尝试创建一个指针数组,其中每个指针都指向一个数组的开头(基本上也是一个指针数组) 我尝试了以下方法:

//declarations:
int* all_paths_of_size_r= (int*)malloc(p_num*sizeof(int)); //p_num is the number of possible paths of size r
int* path = (int*)malloc(r*sizeof(int));

我在我写的递归函数中使用它们:

*(all_paths_of_size_r + place_in_arr) = path[0];
free(path);
place_in_arr++;
adds++; // this is an int that tells me if there are no more possible paths of size r so that i can free the last malloc I created within the function
int* path = (int*)malloc(r*sizeof(int));
if(adds==how_many_paths_of_size_r_could_be_generated_of_set_N(r, N)) //set N is the numbers from 0 to N-1
    free(path);

现在,我正在尝试访问 all_paths_of_size_r 指向的这些数组中的每一个(我的意思是我正在尝试访问每个数组以检查它的最后一个数字是否为 x),我该怎么做?

0 个答案:

没有答案
相关问题