The point is that we want to use this program with any file of numbers. The number of values in the file can vary and so it is not known when the program is written.
How can we do this?
- Initially create a dynamic array of size, say 10.
- Keep track of the array size and how many elements have been stored in it.
- If the array fills up
- create another one of twice the size
- copy the values from the old array into the new array
- insert the new item and increment the element count
Problem: This causes a memory leak!