int *p = new int(10);
cout<<*p<<endl;
int *p2 = new int[12];
delete p;
delete[] p2;//注意中括号
new一个对象
- 分配内存(operator new)
- 调用构造函数
delete一个对象
- 调用析构函数
- 释放内存
int *p = new int(10);
cout<<*p<<endl;
int *p2 = new int[12];
delete p;
delete[] p2;//注意中括号