Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

To where does a pointer point after being deleted?

When we use delete for a pointer (delete p;), and don't use nullptr for it then, it points to some else location in memory. Can that new location have a valid value so that we can use it in the code?

like image 641
Franky Avatar asked Oct 20 '25 13:10

Franky


1 Answers

Whether a pointer points to the same location or a different location after it has been deleted is not specified by the language. An implementation is free to do whatever they wish to do with the value of that pointer.

Can that new location have a valid value so that we can use it in the code?

That's up to your code. The compiler is not required to do so.

like image 120
R Sahu Avatar answered Oct 22 '25 04:10

R Sahu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!