Dynamic Memory Allocaion
Dynamic Memory Allocaion
Algorithms
Author: Hafiz Abdul Rehman
Instructor: Hafiz Abdul Rehman
Lecture 03 – Dynamic Memory Allocation
Dynamic Memory Allocation
Example
Int size;
// Ask the user for the size of the array
std::cout << "Enter the size of the array: ";
std::cin >> size;
Int* numbers = new int[size]
Resizing of Dynamic Array
Why Dynamic Resizing is Necessary?
1. In many cases, the size of data structures is not known in advance.
2. Fixed-size arrays can be inefficient or impractical.