0

I am having trouble with following fragment of my code giving error:

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);

Here is my code fragment:

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;
}

what's going wrong?

NOTE: This init() function would be called for every test case, so I am clearing memory and arr, min, top1 are global

piyushj
  • 1,546
  • 5
  • 21
  • 29
Naveen Kumar
  • 384
  • 2
  • 11
  • 31

0 Answers0