c++ - memory content not erased after deleting my pointer (on a simple example) -
this question has answer here:
here simple of example of question have: create pointer of integer (value 5), print pointer (hence address) of memory case points to, content (5).
then delete pointer, supposed delete content in memory case has address of pointer. when print a , content, expected address still exists. nevertheless content remains same (5) if a not deleted... explain me? :-)
#include <iostream> int main() { int * = new int(5); std::cout<< << std::endl; std::cout<< "--------" << std::endl; delete a; std::cout<< << std::endl; std::cout<< *a << std::endl; // end of main return 0; }
result:
0x7fff28403a90 -------- 0x7fff28403a90 5
it may or may not print same value after delete operation. observing undefined behavior.
Comments
Post a Comment