我想分配和初始化一個函數內的數組,但我似乎無法在返回後取值。在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