Dynamic Memory Allocation in C
Notes:
Dynamic Memory Allocation in C Programming Language:
- C programming language allows us to allocate, reallocate and de-allocate memory locations at run time i.e. during the execution of a program or an application.
- Allocating, reallocating and de-allocating memory locations at runtime is called dynamic memory allocation
- To allocate, reallocate and de-allocate memory locations at run time; we take help of 4 built in functions; which are available inside stdlib.h header file. They are malloc(), calloc(), realloc() and free() functions
Note: To use malloc(), calloc(), realloc() and free() functions inside any c program; we must include stdlib.h header file.
- malloc() and calloc() functions are used to allocate memory locations at run time
- realloc() function is used to reallocate or resize an already allocated memory location at run time
- free() function is used to de allocate an already allocated memory location at run time