i have a struct such as
typedef struct bignum {
long number_of_digits;
char *digit;
} bignum;
and i want to declare an array of type bignum, the array size is going to be changed dynamically , so i used malloc()
, realloc()
can i shrink the array using realloc()
with out memory leakes.
sample of shrinking code
if(free_slots == 50)
{
big_num_Arr =(bignum *) realloc (big_num_Arr,(capacity-40)*sizeof(bignum));
free_slots = 10;
capacity -= 40;
}