#include <iostream>
using namespace std;
//内存管理
//内存的本质是资源,由操作系统掌管内存资源
//申请/归还内存资源就是内存管理
//申请内存:运算符new:int*p = new int;int *arr = new int[10];
/*
申请内存需要判断是否成功
int *p = new int[1000];
if (NULL == p)
{
//内存分配失败
}
*/
//释放内存:delete运算符:delete p;delete []arr;
//释放内存需要设空指针:p=NULL;
int main()
{
int *p = new int(10);
if (NULL == p)
{
cout << "error" << endl;
system("pause");
return 0;
}
cout << *p << endl;
delete p;
p = NULL;
p = new int[100];
if (NULL == p)
{
cout << "error" << endl;
system("pause");
return 0;
}
p[0] = 1;
p[1] = 2;
cout << p[0] << p[1] << endl;
delete []p;
p = NULL;
system("pause");
return 0;
}