What is Dynamic Memory allocation in c ?Explain each DMA functions with Example

What is Dynamic Memory allocation(DMA) ? Explain each DMA functions

Dynamic Memory allocation refers to the memory allocation to the process at run time. This memory comes from the heap area of memory segment in process.

 C provides features for allocating and deallocating the memory from heap area which is knowns as dynamic allocation and deallocation.

 

C function used for Dynamic Memory allocation :

library : stdlib.h 

Function

Description

malloc

allocates the specified number of bytes

realloc

increases or decrease the size of the specified block of memory. Reallocates it if needed

calloc

allocates the specified number of bytes and initializes them to zero

free

releases the specified block of memory back to the system

Usage :

To allocate n sizeof(int) block of memory

using malloc

 

 

Using calloc

 

 

 

Using realloc

 

 

%d bloggers like this: