Dear all,
I am learning about pointers in C++. I practice creating a pointer then delete it when I do not need. I use "delete pointer". However the following code seems does not work as expected.
Please help me to point out it.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#include<iostream>
usingnamespace std;
int main(){
int *ptr;
ptr=newint;
if (ptr==NULL){
cout<<"Memory allocation failure!"<<endl;
return -1;
}
cout<<"Pointer before deleting:"<<ptr<<endl;
//Delete the pointer
delete ptr;
//Deference it
*ptr=3;
cout<<"The pointer is still here [???]:"<<ptr<<endl;
}