Skip to content

Latest commit

 

History

History
6 lines (4 loc) · 827 Bytes

File metadata and controls

6 lines (4 loc) · 827 Bytes

Explain the difference between "malloc" and "calloc" functions in C programming.

Both malloc() and calloc() are memory allocation functions in C programming, but there is a difference between them.

malloc() function is used to allocate a block of memory of a specified size in bytes. It returns a pointer to the first byte of the allocated memory. The allocated memory is not initialized, which means that the memory block contains garbage values that may cause errors in the program if not properly initialized.

On the other hand, calloc() function is used to allocate a block of memory of a specified size in bytes and initialize all the memory bits to zero. It takes two arguments: the number of blocks to be allocated and the size of each block in bytes. It returns a pointer to the first byte of the allocated memory.