+ 1
Question related to the delete oprerator for a pointer
int *ptr=new int; *ptr=10; delete ptr; cout<<*ptr; still printing 10 as the output after i had freed the memory which has stored the value 10. i dont understand why?
1 Odpowiedź
+ 2
Memory keeps the same values till it’s overwritten. The delete operator just frees the memory, it does not overwrite the memory. After deleting a pointer, dereferencing it is undefined behavior.