Dynamic Arrays:
We created arrays at compile time . array created at compile time by specifying size in the source code has a fixed size and can not be modified at run time.
The process of allocating memory at compile time is known as static memory allocation and the arrays that receive static memory allocation are called static arrays.
This approach works fine as long as we know exactly what our data requirement are.
Consider are situation where we want to use an array that can vary greatly in size.
We must guess what will be the largest size even needed and create the array accordingly.
A difficult task in fact! Modern languages like c do not have this limitation.
In c it is possible to allocate memmory to arrays at run time.
This featureis known as dynamic memory allocation and the arrays created at run time are called dynamic arrays.
This effectively postpone the array definition to run time.
Dynamic arrays are created using what are known as pointer variable and memory management functions molloc, and calloc realloc.
These functions are included in the header file <stdlib.h>.
The concept of dynamic arrays is used in creating and manipulating data structures such as linked lists,stacks and queues.
No comments:
Post a Comment