C calloc() function
Calloc Function : Dynamic memory allocation
ptr = (data_type *)calloc(No_of_elements ,sizeof(data_type));
Live Exampleptr = (int *) calloc(10,sizeof(int));
- calloc :
- Header File : stdlib.h
- Allocate 20 bytes of memory
- Sizeof Returns the Size of Parameter specified
- 10 means allocate space at run time for 10 elements
- (int *) means Typecasting i.e Address of Block of memory is casted to address of Pointer
- On Success : 20 bytes will be allocated
- On Fail : Returns NULL
- Memory Address is assigned to Pointer ptr
- Calloc is more efficient than malloc because it allocates memory in 1 clock cycle
- Calloc takes 2 arguments
- Allocates memory Block of n*sizeof(data_type )
- Clears allocated memory with Zero