下载此文档

过期指针、new、delete.doc


文档分类:办公文档 | 页数:约4页 举报非法文档有奖
1/4
下载提示
  • 1.该资料是网友上传的,本站提供全文预览,预览什么样,下载就什么样。
  • 2.下载该文档所得收入归上传者、原创者。
  • 3.下载的文档,不会出现我们的网址水印。
1/4 下载此文档
文档列表 文档介绍
【C++】关于过期指针及new 、 delete
// : 定义控制台应用程序的入口点
//此段程序展示一些关于过期指针的表现
#include ""
#include <iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
int *i;
i=new int;
cout<<"Input *i : ";
cin>>*i;
int *ptr=i;
cout <<" i "<<i<<endl;
cout<<" ptr "<<ptr<<endl;
cout<<endl;
cout <<" &i "<<&i<<endl;
cout<<" &ptr "<<&ptr<<endl;
cout<<endl;
cout <<" *i "<<*i<<endl;
cout<<" *ptr "<<*ptr<<endl;
cout<<endl;
delete i;
//delete ptr;
cout<<" ****** delete I ***********\n\n";
cout <<" i "<<i<<endl;
cout<<" ptr "<<ptr<<endl;
cout<<endl;
cout <<" &i "<<&i<<endl;
cout<<" &ptr "<<&ptr<<endl;
cout<<endl;
cout <<" *i "<<*i<<endl;
cout<<" *ptr "<<*ptr<<endl;
cout<<"\n *************new ***********\n\n";
int *ne= new int(4);
cout<<" *ne "<<*ne<<endl;
cout<<" &ne "<<&ne<<endl;
cout <<" ne "<<ne<<endl;
cout<<"\n ***************************\n\n";
cout <<" i "<<i<<endl;
cout<<" ptr "<<ptr<<endl;
cout<<endl;
cout <<" &i "<<&i<<endl;
cout<<" &ptr "<<&ptr<<endl;
cout<<endl;
cout <<" *i "<<*i<<endl;
cout<<" *ptr "<<*ptr<<endl;
cout<<" ****** delete ne ***********\n\n";
delete ne;//
cout<<" *ne "<<*ne<<endl;
cout<<" &ne "<<&ne<<endl;
cout <<" ne "<<ne<<endl;
cout<<"\n ***************************\n\n";
cout <<" i "<<i<<endl;
cout<<" ptr "<<ptr<<endl;
cout<<endl;
cout <<" &i "<<&i<<endl

过期指针、new、delete 来自淘豆网m.daumloan.com转载请标明出处.