1
我在分配內存後得到了關於這個int數組初始化的小問題。我得到了以下錯誤:int malloc初始化後的數組
"Line 7 Error: expected expression before '{' token"
這是我的代碼:
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i;
int *x=malloc(3*sizeof(int)); //allocation
*x={1,2,3}; //(Line 7) trying to initialize. Also tried with x[]={1,2,3}.
for(i=0;i<3;i++)
{
printf("%d ",x[i]);
}
return 0;
}
有沒有其他辦法,我做的內存分配後,初始化我的數組?