int *f, *l;
int main(){
int *a;
a = calloc(1, sizeof(int));
f = l = a;
put(&a, 1);
put(&a, 3);
put(&a, 2);
_getch();
return 0;
}
void put(int **a, int d){
printf("--%d--", sizeof(*a)); //always == 4
void *tmp = (int *)realloc(*a, sizeof(*a) + sizeof(int));
if (temp) //allocated succesfully
*a = temp;
else
printf("Allocating a failed");
l++;
}
我試圖創建一個基於int指針的隊列模型。realloc不起作用
我已經糾正了一下這個例子。但它仍然失敗。 你能幫忙嗎?
'tmp'或'temp'? – qrdl
你永遠不會引用參數「d」...?你的代碼並沒有真正做任何事情。每個realloc與最後一個尺寸相同,因此不會執行任何操作,而是返回原始指針。 – noelicus