deleteは何をしましたか?
一言でまとめると、ポインタが指すメモリを解放しただけで、そのメモリを再利用することができ、ポインタdeleteの後にnullを指さす必要があります.
実行結果:
bogon:~ zhaojunyan$ g++ -o main main.cpp
bogon:~ zhaojunyan$ ./main
random value of *p: 0
the address of p: 0x7fff52899b70
the value of p(point address): 0x7fdd3b6030c0
the value of *p : 789
delete p
the address of p: 0x7fff52899b70
the value of p(point address): 0x7fdd3b6030c0
the value of *p: 789
bogon:~ zhaojunyan$
#include
using namespace std;
int main()
{
int *p = new int;
cout << "random value of *p: " <
実行結果:
bogon:~ zhaojunyan$ g++ -o main main.cpp
bogon:~ zhaojunyan$ ./main
random value of *p: 0
the address of p: 0x7fff52899b70
the value of p(point address): 0x7fdd3b6030c0
the value of *p : 789
delete p
the address of p: 0x7fff52899b70
the value of p(point address): 0x7fdd3b6030c0
the value of *p: 789
bogon:~ zhaojunyan$