我想分配和初始化一个函数内的数组,但我似乎无法在返回后取值。在c函数中分配数组
这是我最后几乎工作尝试
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int func(int **thing);
int main() {
int *thing;
func(&thing);
printf("%d %d", thing[0], thing[1]);
}
int func(int **thing) {
*thing = calloc(2, sizeof(int));
*thing[0] = 1;
*thing[1] = 2;
printf("func - %d %d \n", *thing[0], *thing[1]);
}
,但打印的功能以外的值是1和0 有很多指针上的文件在那里,但我还没有发现这种特定的案件涵盖。关于我在做什么的任何提示都是错误的?
由于运算符的优先级,可能有问题吗?我会尝试用“(* thing)[x]”替换所有“* thing [x]”。 – Bwmat 2010-11-14 19:43:48