C++内存管理

来源:互联网 发布:视频监控客户端软件 编辑:程序博客网 时间:2024/04/29 18:20

#include <iostream>
#include <stdlib.h>
using namespace std;
int main()
{
    int *p= new int;
    if(NULL==p)
    {
        system("pause");
        return 0;
    }
    *p=20;
    cout<<*p<<endl;
    delete p;
    p==NULL;
    system("pause");
    return 0;
}

//管理块内存

#include <iostream>
#include <stdlib.h>
using namespace std;
int main()
{
    int *p= new int[1000];
    if(NULL==p)
    {
        system("pause");
        return 0;
    }
    p[0]=10;
    p[1]=20;
    cout<<p[0]<<' '<<p[1]<<endl;
    delete []p;
    p==NULL;
    system("pause");
    return 0;
}

0 0
原创粉丝点击