Error in this code?

I have been told by my professor that there is an error in this code but it compiles just fine. He said that it had a simple common error. Any help with a brief explanation would be greatly appreciated.

#include <iostream>
using namespace std;

int main()
{
short * pPtr;
pPtr= new short;
*pPtr= 1;
cout << "*pPtrValue: " << *pPtr<< "\tMemory Address: " << pPtr<< endl;
pPtr= new short;
*pPtr= 5;
cout << "*pPtrValue: " << *pPtr<< "\tMemory Address: " << pPtr<< endl;
delete pPtr;
pPtr=0;
return 0;
}
You have a memory leak.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
int main()
{
     short * pPtr;

     pPtr= new short;//1
     *pPtr= 1;

     cout << "*pPtrValue: " << *pPtr<< "\tMemory Address: " << pPtr<< endl;

     pPtr= new short;//2 

     *pPtr= 5;
     cout << "*pPtrValue: " << *pPtr<< "\tMemory Address: " << pPtr<< endl;

     delete pPtr;//1
     pPtr=0;
     return 0;
}


see the problem?
Topic archived. No new replies allowed.