Code:
cout << "*pInt = " << *pInt << "\tpInt = " << pInt << endl;
delete pInt;
//pInt = 0;
long * pLong = new long;
*pLong = 90000;
cout << "*pLong = " << *pLong << "\tpLong = " << pLong << endl;
Perhaps you should print where the allocated memory is, and NOT the address of the pointer.
Here, you're likely to see that pInt and pLong point to the same bit of memory.
Which is allowed since you deleted your pInt and now that memory is being used for pLong.
Then you come along and break all the rules with *pInt = 10 ;
You broke your "promise", you hadn't finished with pInt at all.
> pInt = 0;
> The program crashes on line 16 when i reassign the value 10 to *pInt.
Good! It keeps you honest.
You basically have to decide
a) did I delete the memory too soon because I needed it
b) the delete was fine, and the assignment is a mistake.
You edit the code accordingly.