my question is will garbage collector will free a memory if the variable allocated is malloced again without freeing the memory.
eg:
ptr1 = malloc(100)
ptr1 = malloc(200)
In this case will the first allocated memory will be deallocated by garbage collector??
If yes then when..???
No, it will result in a memory leak.
There is no garbage collector in C.
You have to do the memory management yourself.