Dynamic Arrays

To allocate an array of 10 ints, you can say int A[10]; or int *A = new int[10]. But what if we want n ints?

	int n;
	n = ... OR cin >> n;
	int *A;
	A = new int[n];

We had no way to do this before. If we say int A[n]; we get an error, unless n is a constant. dynamicIntArray.cpp shows proper use of this new method. Note that deleting this allocated memory is a little different. We have to tell the compiler that there is an array at the end of the pointer by saying delete [] A;.

Destructor

A member function of a class that is automatically executed when the object is deleted. There are two times that objects are deleted: