Suppose we have this code:
int *h; for(int i=0;i<5;i++){ h = malloc(sizeof(int)); h[i] = i; } The issue I have here is that I want to start with an empty array, i.e. just declaringint *h, and then *h will grow at the runtime using realloc. I tried using this example but it does not allocate a sequential memory places and also does not work. I understand that realloc works after allocating by malloc so is there any workaround of that?
h = malloc(sizeof(int));allocates only aninth[0]and leaking the previoush