+ 4

Can anyone clearly explain about malloc() , calloc() , realloc() function???

29th May 2019, 4:48 PM
Bala Kumaran
Bala Kumaran - avatar
5 Antworten
+ 15
Bala Kumaran calloc() Same principle as malloc(), but it's used to allocate storage. The real difference between these two, is that calloc() initializes all bytes in the allocation block to zero, because it's used to reserve space for dynamic arrays. It's written like this. source: https://medium.com/@jraleman/c-programming-language-functions-malloc-calloc-realloc-and-free-61cfc3e45da7 malloc() In C, the library function malloc is used to allocate a block of memory on the heap. The program accesses this block of memory via a pointer thatmalloc returns. When the memory is no longer needed, the pointer is passed to free which deallocates the memory so that it can be used for other purposes. source: wikipedia realloc() The C library function void *realloc(void *ptr, size_t size)  attempts to resize the memory block pointed to by ptr that was previously allocated with a call to malloc or calloc. source: https://www.tutorialspoint.com/c_standard_library/c_function_realloc.htm I hope I was helpful
29th May 2019, 4:52 PM
Alessio Benvenuti
Alessio Benvenuti - avatar
+ 3
Malloc- This just allocates the specified memory. Calloc- Allocates contiguous block of memory for something like array. realloc- Re allocates memory for the specified pointer.
29th May 2019, 4:54 PM
Akib
Akib - avatar
+ 3
dear devanille, can you explain memory management functions such as malloc(), calloc(), realloc & free () with example program
30th May 2019, 2:51 AM
Bala Kumaran
Bala Kumaran - avatar