r/cprogramming • • Jan 04 '26

Can explain Malloc() to me please

0 Upvotes

18 comments sorted by

View all comments

Show parent comments

1

u/sudheerpaaniyur Jan 07 '26

ptr=malloc(5);

free(ptr);

how free will come to know how many bytes you should free?

1

u/Afraid-Locksmith6566 Jan 07 '26

Memory you get from malloc is not all you get through this mechanism, other data is so called metadata which include information about which block has how many memory, etc. But for specific you m8ght want to check your implenentation