0

Y does the pointer shows 88 even after getting deleted?

#include <iostream> int main(){ int *pointer = new int; *pointer = 88; std::cout << "*Pointer : " << *pointer << std::endl; delete pointer; std::cout << "*Pointer : " << *pointer << std::endl; return 0; }

10th Oct 2017, 4:37 PM
suryapoojary
suryapoojary - avatar
3 Answers
+ 15
Thank you Mr.JPM7 for pointing out to this new standard facility.
10th Oct 2017, 7:38 PM
Babak
Babak - avatar
+ 14
You need to nullify your pointer. delete pointer; *pointer = 0; and not (since you'd use it on the next cout - otherwise you should use the below instead of *pointer = 0) // pointer = 0; // Access violation reading location 0x00000000. std::cout << "*Pointer : " << *pointer << std::endl;
10th Oct 2017, 4:49 PM
Babak
Babak - avatar