Why we go for dynamic allocation of 2D array. We can simply write arr[m][n] after declaring m and n. So, explain how we use double pointer and also its implement.
Why we used double pointer like this **arr
Reasons and Advantage of allocating memory dynamically:
- When we do not know how much amount of memory would be needed for the program beforehand.
- When we want data structures without any upper limit of memory space.
- When you want to use your memory space more efficiently. Example: If you have allocated memory space for a 1D array as array[20] and you end up using only 10 memory spaces then the remaining 10 memory spaces would be wasted and this wasted memory cannot even be utilized by other program variables.
- Dynamically created lists insertions and deletions can be done very easily just by the manipulation of addresses whereas in case of statically allocated memory insertions and deletions lead to more movements and wastage of memory.
- When you want you to use the concept of structures and linked list in programming, dynamic memory allocation is a must.
for this you can refer this
if you want to ask something about this feel free to ask here
i hope this helps
if yes show your response with and don’t forgot to mark doubt as resolved