Use of malloc and calloc?

Answer:

Answer

The use of malloc and calloc is dynamic memory allocation. malloc allocates memory in bytes whereas calloc allocates memory in blocks. calloc initializes the allocated memory to zero. Both differs in number of arguments also. malloc takes only one argument and allocates the memory in bytes as given in the argument. calloc takes two arguments, number of variables to be allocated and size of each variable. Another difference is how the two functions deal with memory alignment.


Actually malloc allocates a block of size bytes from memory heap. It allows a program
to allocate memory as its needed, and in the exact amount needed . Where as calloc provides access to the C memory heap, which is available for dynamic allocation of
variable-sized block of memory.
First answer by Rajeshgopan. Last edit by Dnyan86. Contributor trust: 2 [recommend contributor recommended]. Question popularity: 15 [recommend question].