Allocating and deallocating arrays at runtime
Arrays may be dynamically allocated so that their size may be determined at runtime. Dynamically allocated arrays may be of any type, including user defined types. Determining the size of an array at runtime can be a space-saving advantage and gives us programming flexibility. Rather than allocating a fixed-sized array of the largest possible quantity needed (potentially wasting space), you can instead allocate the necessary size determined by various factors at runtime. You have the additional flexibility to delete and reallocate an array should the need arise to change an array’s size. Arrays of any number of dimensions can be dynamically allocated.
In this section, we will examine how to dynamically allocate arrays of both basic and user defined data types, and of single and multiple dimensions. Let’s get started.
Dynamically allocating single dimension arrays
Single-dimension arrays may be dynamically allocated...