Without delete int_ptr; there will be a memory leak!
To create a dynamic array we can use the new[] operator.
int *intVar;
intVar = new int[100]; // dynamic array
for(int i = 0; i < 100; ++i)
intVar[i] = 25-i; // initialize the array
delete [] intVar; // frees the allocated array
You have to be careful if you have something like a pointer to an array of pointers, ...
Person **p = new Person* [2];
p[0] = new Person("Peter");
p[1] = new Person("Alex");
Using delete[] p; just causes the p pointer to be released, not the actual objects themselves. You could step through the different index values and use delete p[index] on each. Or, as will probably be discussed later, you could use a wrapper class.
float **fVar;
fVar = new float* [10]; // allocate pointer array, 10 float pointers
for(int i = 0; i < 10; ++i)
fVar[i] = new float[10]; // allocate memory to each
. . . .
. . . .
for(int i = 0; i < 10; ++i)
delete [] fVar[i];
delete [] fVar;
A pointer that points to the memory address of an object that has already been deleted is known as a dangling pointer in C++.