I declared an array and take input from user. Now i want to check duplicate entries, they have to be deleted and memory should be freed. Is it possible to free memory.
freeing the unused memory and reducing the array size?
I entered [10,21,3,4,4,2,6,7,21,4,10].it should get truncated as [10,21,3,4,2,6,7] and array length should now be 7,and i don’t want to use sorting.
I declared an array of length 100 and took input from user
so you mean like this:
Is it possible to free memory
the answer is no because you statically allocate 100 integers.
If you want to be able to reduce memory then you should do something like this:
Another solution is to
realloctempBufferafter arranging the firstuniqueNentries to be the unique entries:don’t forget to check if
mallocorreallocreturnsNULL