Kevin Meredith Kevin Meredith - 4 months ago 58
C Question

C - calloc() v. malloc()

Possible Duplicate:

c difference between malloc and calloc

Please explain the significance of this statement,

difference between the malloc() and
calloc() functions is that the memory
allocated by malloc( ) function
contains garbage values, while memory
allocated by calloc( ) function
contains all zeros.

Source ('C' Programming, Salim Y. Amdani)




malloc() is faster, since calloc() initializes the allocated memory to contain all zeros. Since you typically would want to use and initialize the memory yourself, this additional benefit of calloc() may not be necessary.