作者在 2008-04-24 19:05:58 发布以下内容
天气: 晴朗
心情: 高兴
为什么(delete pheap; pheap=new int;)两个或其中的一个可去可不去,两种情况执行结果一样。
#include<iostream.h>
int main()
{
int localvariable=5;
int *plocal=&localvariable;
int *pheap=new int;
*pheap=7;
cout<<"localvariable:"<<localvariable<<endl;
cout<<"*plocal:"<<*plocal<<endl;
cout<<"*pheap:"<<*pheap<<endl;
delete pheap;
pheap=new int;
*pheap=9;
cout<<"*pheap:"<<*pheap<<endl;
delete pheap;
return 0;
}