C++ Primer For Java Programmers Dynamic Arrays<< | Table of Contents | >>
C++ Dynamic ArraysTo create a dynamic array using the C++ approach, the int *myGrades = new int[ NUM_GRADES ]; myGrades[ 0 ] = 85; myGrades[ 1 ] = 90; myGrades[ 2 ] = 87; myGrades[ 3 ] = 65; myGrades[ 4 ] = 91; we create a five element Note that the array itself is dynamic but it does not contain dynamic elements. You will also notice the use of the pointer notation to specify the array pointer variable. Deleteing Dynamic Arrays.
As with any dynamic variable, you are responsible for deallocation when the dynamic memory is no longer needed. The delete myGrades; You can only delete an array which was created using the C Dynamic ArraysDynamic Pointer Arrays
|