【发布时间】:2014-06-12 23:01:49
【问题描述】:
我想初始化一个 n*n 方阵,以便稍后通过引用将其传递给另一个函数。但它甚至没有编译。我已经尝试了所有方法,请帮助。
#include<stdlib.h>
int main()
{
int i, j, n = 3;
float **a;
a = malloc(n * sizeof (float **));//Here I try to create the n pointers to pointer to float for the rows
for(i = 1;i <= n;i++){
a[i] = malloc(n * sizeof(float *)); //Here I try to create the n * n pointers to float for the columns
for(j = 1;j <= n;j++)
*(*(a + i - 1) + j - 1) = malloc(sizeof(float)); //Here I try to free the space for the elements
return 0;
}
【问题讨论】:
-
"It doesn't compile" 你得到什么错误信息,在哪一行?
-
另外,这不是递归。
-
你尝试了一切?在莫斯科编程俱乐部,我们将候选人的长子和老鼠一起锁在地下室,直到算法正常工作。 这就是你看到真正动机的地方。
-
哥们,不要像其他人一样写
*(A+i),不如写A[i]? -
@KerrekSB:啊。现在我明白为什么俄罗斯是 ACM ICPC 的世界冠军了……