What is dynamic memory allocation? Explain all it's types. (12 marks)
Answers
Dynamic memory allocation is when an executing program requests that the operating system give it a block of main memory. The program then uses this memory for some purpose. Usually the purpose is to add a node to a data structure. ... Programs may request memory and may also return previously dynamically allocated memory.
Answer:
Dynamic memory allocation is defined as
Explanation:
C is a programming language and a structured language, As it also contains some fixed rules and regulations for programming. Among these rules, one of it changing the size of an array.
Array- An array is a collection of items that is stored at continuous memory locations.
Example- As for the understanding of concept we take an array of length (size) of 9. But during the programming if some user wants to increase or decrease the size of array or what if there is requirement to change this given length (size).
For Instance- There is a situation where user want to enter 5 elements and only 5 elements are needed to be entered in the array. In the given array, the remaining 4 indices , wasting memory in of the array. So there is a requirement or need to lessen the length of the array from 9 to 5 as per the need.
While taking another case. In this case, An array given of 9 indices, all the indices are filled as the allotted memory have occupied the place. But the user wants to enter 3 more Elements in the array. So 3 indices more are required. So the length (size) of the array needs to be increased and changed from 9 to 12.
This procedure which is explained above is referred to as Dynamic Memory Allocation in C.
This procedure is used by many functions like calloc(), malloc() etc.