5.new和delete

来源:互联网 发布:u盘数据恢复公司 编辑:程序博客网 时间:2024/06/05 07:09
 #include <iostream> int main(void){    using namespace std;    int night = 1001;    int * pt = new int;    *pt = 1001;    cout<<"night value = "<<night<<" ; location "<<&night<<endl;    cout<<"int "<<"value = "<<*pt<<" ; location "<<pt<<endl;    double *pd = new double;    *pd = 10001.0;    cout<<"double value = "<<*pd<<" ; location "<<pd<<endl;    cout<<"size of double = "<<sizeof(double)<<"; size of pd : "<<sizeof(pd)<<" size of *pf : "<<sizeof(*pd)<<endl;    cout<<"size of int = "<<sizeof(int)<<"; size of pt : "<<sizeof(pt)<<"size of *pt : "<<sizeof(*pt)<<endl;    delete pd;    cout<<"delete pd"<<" pd is :"<<pd<<endl;    delete pt;    cout<<"delete pt"<<" pt is :"<<pt;     return 0; }

new和delete相当于malloc和free

0 0
原创粉丝点击