Can any one Explain me plz the concept of Growing Array Of Structs. i mean dynamic Arrays. thanks for your Time.
Start with a small array of some size, then whenever you need to increase the size, use realloc to do so; it is common to double the size of the array whenever you resize it.
For example:
int length = 5;
my_struct *array = NULL;
/* Initialization */
array = (my_struct *)malloc(length * sizeof(my_struct));
/* Use array[0] .. array[length - 1] */
/* When you reach the limit, resize the array */
length *= 2;
array = (my_struct *)realloc(array, length * sizeof(my_struct));
Do you mean dynamic size of an array? In that case you must allocate memory fitting for you needs. See realloc
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With