What is the difference between dynamic array and associative array? which is the best one to use?
Where will we use dynamic/associative arrays.
Dynamic Array :-
-
We use dynamic array when we have no idea about the size of the array during compile time and we have to allocate its size for storage during run time.
-
Array indexing is integer type only…and it store contiguous data
-
When we have need of contiguous data and don’t know size of it at compile time dynamic array comes to rescue
Associative Array :-
-
But when we deal with “key and it’s value” kind of data we need associative array…suppose we verify some processor’s memory ex. 4k bytes where we don’t use whole address we need only some address to give value than despite using dynamic array use associative array .
-
Index of associative array can be any data type…it will work as key.
-
Associative array add extra overheads but save lots of memory space at run time…