Calloc Function ( Dynamic Memory Allocation Part -3 )
Definition
Calloc function allocates series of similar bock of elements in the heap which is executed and allotted at the runtime of the program execution. As the program instructions cannot directly access heap memory, so a pointer is required which points to the memory address of the first memory byte allocated by the calloc function in heap.The calloc returns a void pointer which is to be type-casted to the convenient data type as in use by the user.
Malloc function is declared under stdlib.h library. So include this in the program in the section of the header files, to avoid getting a warning or syntax error in certain compilers.
The general syntax of the calloc function is :
For storing float in the dynamic memory we can use :< data_type> *pointer;
pointer = ( < type casting * > ) calloc(< number of elements >,< byte_size >)
float *pointer;
pointer= ( float* )calloc(5,sizeof( float ))
A program using calloc function :
A similar method of doing the same problem
Comments
Post a Comment