如何在C中处理动态多维数组?有人知道我如何使用C来动态分配多维数组吗?这有可能吗?
3 回答
狐的传说
TA贡献1804条经验 获得超3个赞
int** x;x = malloc(dimension1_max * sizeof(int*));for (int i = 0; i < dimension1_max; i++) { x[i] = malloc(dimension2_max * sizeof(int));}[...]for (int i = 0; i < dimension1_max; i++) { free(x[i]);}free(x);
dimension1_max
* dimension2_max
dimension1_max
= 640, dimension2_max
x[d1][d2]
d1
= 0..639, d2
= 0..479.
int** x;int* temp;x = malloc(dimension1_max * sizeof(int*));temp = malloc(dimension1_max * dimension2_max * sizeof(int));for (int i = 0; i < dimension1_max; i++) { x[i] = temp + (i * dimension2_max);}[...]free(temp);free(x);
慕神8447489
TA贡献1780条经验 获得超1个赞
double (*A)[n] = malloc(sizeof(double[n][n]));
A[i][j]
free(A);
- 3 回答
- 0 关注
- 589 浏览
添加回答
举报
0/150
提交
取消