【发布时间】:2012-10-23 21:44:00
【问题描述】:
我尝试过使用三重指针,但总是失败。代码:
#include <stdlib.h>
#include <stdio.h>
int set(int *** list) {
int count, i;
printf("Enter number:\n");
scanf("%d", &count);
(*list) = (int **) malloc ( sizeof (int) * count);
for ( i = 0; i<count;i++ ) {
(**list)[count] = 123;
}
return count;
}
int main ( int argc, char ** argv )
{
int ** list;
int count;
count = set(&list);
return 0;
}
感谢您的建议
【问题讨论】:
-
我很久以前就给自己定了一条规则,如果我的代码在任何地方都有
***,我必须重写它。 -
我听说过这个规则,但是在这种情况下,***将节省创建一个只会被调用一次的函数。
-
不,这并不意味着重新编码,而是意味着重新设计您的数据结构,以便您不需要所有这些间接层。
-
你应该使用
(**list)[i]=123而不是(**list)[count]=123 -
义务“三星级程序员”笑话:webcache.googleusercontent.com/…
标签: c arrays pointers allocation