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; }
3 Antworten
+ 15
Thank you Mr.JPM7 for pointing out to this new standard facility.
+ 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;