Dynamic memory allocation introduction

The process of allocating memory during program execution is called Dynamic Memory Allocation.
The exact size of an array is unknown until the compile time. The size of array that you have declared initially can be sometimes insufficient and sometimes more than required. Dynamic Memory Allocation allows a program to obtain more memory space, while running or to release space when no space is required.
Dynamic Memory Allocation in c language is possible by 4 functions of stdlib.h header file.
  • malloc()
  • calloc()
  • realloc()
Above three functions Allocates a block of memory on the heap
  • free()
free() Deallocates a block of memory on the heap
In order to use these 4 functions, header file <stdlib.h> has to be added.

E.g.

#include<stdlib.h>

Post a Comment

0 Comments