+ 2
I don't quit understand the difference between malloc and calloc since both allocate memory contiguously
3 Respuestas
+ 5
Brian Kimathi malloc only allocates memory and does not change the garbage values that it contains, whereas calloc allocates and clears the memory by filling with 0. Use malloc when the program will fill the memory afterward. Use calloc when you need the memory cleared from garbage values immediately.
+ 3
malloc allocates a chunk of memory.
calloc allocates a chunk of memory and sets all it's bytes to zero (no garbage values).
use realloc for changing the allocated chunk's size (it will copy your data, and extend or shrink the size of allocated memory as you specify).
+ 2
for calloc;- http://www.cplusplus.com/reference/cstdlib/calloc/
for malloc:- http://www.cplusplus.com/reference/cstdlib/malloc/