Please consider a heap-allocated array of pointers like this:
Thing** array = malloc(sizeof(Thing*) * array_length);
How can I set all of its members to NULL
?
I can of course do this:
for (int i = 0; i < array_length; i++) {
array[i] = NULL;
}
But I'm wondering if there's a standard function for this.
SO mainly mentions memset
, however I'm not sure it is guaranteed to work on all platforms for this usecase, since as far as I understand it walks the array byte by byte, and not element by element.
Also more generally, what is the standard way to set all values in an array of any type T
, which can be of any size, to some particular value?