Malloc , calloc, free and realloc in C
3071
29-Oct-2016
Updated on 20-Sep-2020
Abhishek Srivasatava
29-Oct-2016Malloc
By using malloc we can create one block of memory requested dynamically which can be used as array etc. and return a pointer to 1st byte.
Here is the small program to learn how to use malloc function.
Calloc:
By using Calloc we can create multiple block of memory requested dynamically which can be used as array etc. it fills the memory to zero and and return a pointer to 1st byte.
Calloc initialize the memory to zero.
Here is the small program to learn how to use calloc function.
Free Function:
To release the memory we need to use Free function;
Syntax: free(num_mal);When we need to change the size of the memory allotted then we need to realloc function.
Syntax: