C语言用malloc函数定义数组

C语言用malloc函数定义数组int n=5;
int arr[n];
我知道这是错的,但这种想法怎么用malloc函数定义

int* arr;
int n = 5;
arr = (int*)malloc(n*sizeof(int));

然后就定义好了呀,这就是你需要的那种malloc分配空间的数组,使用结束需要释放掉,free(arr)。
温馨提示:答案为网友推荐,仅供参考
相似回答