Dynamic Memory
Dynamic Memory
Module-3
Since C is a structured language, it has some fixed rules for programming. One of them includes changing the size
of an array.
Here,the length (size) of the array above is 9. But what if there is a requirement to change this length (size)? For
example,
If there is a situation where only 5 elements are needed to be entered in this array. In this case, the remaining 4
indices are just wasting memory in this array. So there is a requirement to lessen the length (size) of the array
from 9 to 5.
Take another situation. In this, there is an array of 9 elements with all 9 indices filled. But there is a need to enter
3 more elements in this array. In this case, 3 indices more are required. So the length (size) of the array needs to
be changed from 9 to 12.
Definition
• The concept of dynamic memory allocation in c
language enables the C programmer to allocate memory at
runtime. Dynamic memory allocation in c language is possible by
4 functions of stdlib.h header file.
• malloc()
• calloc()
• realloc()
• free()
Difference between static memory allocation and dynamic
memory allocation.