I have a pointer to an array. I know how many number of items that array can hold but the length of each item is dynamic. So how to memset()
the array in this case.
Int8 *data[4]; //array can hold maximum of 4 elements
Also I want to allocate memory for each item. How to do this?
First, you initialize the array at definition time by saying,
Then, you need to use a loop to allocate memory to each element of the array, like
FWIW,
calloc()
will returned "zero"ed memory (if success), so no need tomemset()
separately if you want the memory to be initialized to0
.Obviously, you need to check for the success of the allocation.