How to delete elements from the middle of a pointer array using free() or any other method?

458 Views Asked by At

I have created a pointer array using calloc and I want to delete elements starting from the middle of the array.What are the ways in which this can be done?

1

There are 1 best solutions below

0
On

You can only pass to free a pointer that was returned from malloc, realloc, or calloc.

If you want to remove a value from the middle of any array (dynamically allocated or otherwise), you need to move each value above it down by one element. You'll also want to keep track of how many "active" elements the array contains in some way.