deleteは何をしましたか?

635 ワード

一言でまとめると、ポインタが指すメモリを解放しただけで、そのメモリを再利用することができ、ポインタdeleteの後にnullを指さす必要があります.
#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$