On the discussion of dynamic memory here: "Intro to C Pointers and Dynamic Memory"
The author states:
A memory block like this can effectively be used as a more flexible array. This approach is actually much more common in real-world C programs. It's also more predictable and flexible than a "variable size array"
The type of memory block he is talking about is as such:
const int size = 5;
int * array = calloc(size, sizeof(int));
and then using another pointer to iterate over the array:
int * index = array;
for (i = 0; i < size; i++) {
*index = 1; // or whatever value
index++;
}
My question is how is this method better than a standard variable sized array like this?:
int array[variable];
or dynamic:
char name[] = "Nick";
The author doesn't really shed much light as to why I should prefer the former method to the latter. Or more specifically: How is it more "predictable and flexible"?