mallo() vs calloc() (#30669)

pull/31439/head^2
Jay Patel 2019-04-02 00:00:39 +05:30 committed by Christopher McCormack
parent de18323c7e
commit 46ae11f958
1 changed files with 5 additions and 0 deletions

View File

@ -30,3 +30,8 @@ This statement will deallocate the memory previously allocated. C does not come
* Allocating memory allows objects to exist beyond the scope of the current block.
* C passes by value instead of reference. Using malloc to assign memory, and then pass the pointer to another function, is more efficient than having the function recreate the structure.
Difference between malloc() and calloc()
1. Malloc() does not assignes the created memory to zero where as calloc() assignes the memory created to zero.
2. malloc() is best suitable for Character data and calloc() for Numeric data.
3. Malloc() can give garbage value if it deals in numeric data as it does not assignes the meory to zero.