Initially mallocate 0 elements to later reallocate and measure size
I have a function that will add a new position to an array by reallocating new memory every time it is called. The problem is that, for each call I need it to add one position to the array, starting from 1 at first call, but I understand that I have to mallocate before reallocating. So my question is, can I initially do something like p = malloc(0) and then reallocate for example using p = (int *)realloc(p,sizeof(int)) inside my function? p is declared as int *p . Maybe with a different syntax? Of course I could make a condition in my function that would mallocate if memory hasn't been