1 Answer
  • 1
Votes
name
name Punditsdkoslkdosdkoskdo

C free and struct

My question is about C free() function for deallocating memory blocks previously allocated with malloc().
If i have a struct data type compose of several pointers, each of them pointing to different memory locations, what would happen to those memory locations if i apply free() on the struct? will that locations be free too? or just the memory block that allocate the pointer?

No. They won't be freed. You have to free them "manually". The malloc knows nothing about the content of your struct (it does not know it is a struct at all, it is just a "piece of memory" from its point of view).

  • 0
Reply Report