Introducing dynamic memory
Do we always know exactly how many objects we will need to manipulate and allocate memory for in a program? The answer is a resounding no!
Not every situation or program can be efficiently addressed using just automatic or static memory. The number of objects may vary widely over the runtime of the program and from one run to another of the same program. The number of objects may depend on inputs from the user (covered in Chapter 20, Getting Input from the Command Line, and Chapter 21, Exploring Formatted Input), from one or more existing files (covered in Chapter 22 Working with Files, and Chapter 23, Using File Input and File Output), another device, or even from a network connection to a remote server.
Furthermore, some problems cannot be easily solved with simple automatic or static memory. These types of problems include sorting algorithms, efficient searching and lookup of large amounts of...