First of all, please use code tags and systematic indentation style.
See http://www.cplusplus.com/articles/jEywvCM9/
Well formatted code is much easier to read.
You can edit your post.
I am supposed to do something to fix a memory leak?
Yes. The comments in code state that rather clearly. They also hint where to do it.
The main thing is less about "fixing" anything, and more about understanding what is going on.
What help do you need? The comments in the program tell you exactly where you need to deal with memory leaks.
PLEASE USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post. http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.
whenever you use the keyword "new" it is always followed by a "delete". You need to delete your pointer once you have used it to fix the memory leak. If you don't call delete you will get memory leaks.
// You'll need a command here to fix the memory leak
cout << endl << " --->Before reallocating memory for nArray." << endl;
cout << " nArray address is <" << nArray << "> and contains the value " << hex << *nArray << endl;
delete[] nArray; //call it here
nArray = newint[arraySize + 2];
cout << dec << " --->After reallocating memory for nArray." << endl;
cout << " nArray address is <" << nArray << "> and contains the value " << hex << *nArray << dec << endl;
for (int i = 0; i < arraySize + 2; i++)
{
nArray[i] = i*i;
}
cout << endl << " --->After reinitializing nArray." << endl;
cout << " nArray address is <" << nArray << "> and contains the value " << hex << *nArray << dec << endl << endl;
for (int i = 0; i < arraySize + 2; i++)
{
cout << " nArray[" << i << "] = " << nArray[i] << " at address <" << nArray + i << ">" << endl;
}
// . . . and also here.
cout << endl << " --->Getting ready to close down the program." << endl;
cout << " nArray address is <" << nArray << "> and contains the value " << hex << *nArray << dec << endl;
delete[] nArray; // and call it here