Calloc() function in C

This “calloc() function in C” post is providing clear information about how to use calloc() function in the allocation of Array in C programming.


 

calloc( ):

  • Allocating memory dynamically for Arrays.
  • It is available in stdlib.h header file.

 

prototype :
void* calloc(size_t n , size_t size);

  • First argument specifies number of elements in array.
  • Second argument specifies “size” of each element.

 

Why return type is void* ?

  • Using calloc(), we can allocate the memory dynamically to any kind of array(int, float, structure…..).
  • void* is called Generic pointer, that can be converted into any kind of pointer through type casting.
  • calloc( ) function allocate n*size bytes memory and returns base address of memory block.
  • Allocate block using calloc( ) function initializes with 0’s.

Calloc function in C



 

Share this