数组初始化给出错误:初始化元素不是常量

时间:2016-05-28 07:06:36

标签: c arrays malloc

我在跟踪代码片段时遇到问题:

solution.c:1:1: error: initializer element is not constant
 int *arr=malloc(sizeof(int)*100000);
 ^
solution.c:2:1: error: initializer element is not constant
 int *min=malloc(sizeof(int)*100000);

这是我的代码片段:

int *arr=malloc(sizeof(int)*100000);
int *min=malloc(sizeof(int)*100000);
int top1;

void init() {
    memset(arr,-1,sizeof(arr));
    memset(min,-1,sizeof(min));
    top1=-1;
}

出了什么问题?

注意:每个测试用例都会调用此init()函数,因此我正在清除内存并且arr, min, top1是全局的

0 个答案:

没有答案