申请内存
申请变量对应的内存
类型 *变量名=new 类型(值);
类型 *变量名=new 类型;
pi=new int(123);
申请多个变量对应的一块内存
类型 *变量名=new 类型[n];
double *pd=new double[5];
释放内存
delete 指针变量名;
delete pi;
delete[] 指针变量名;
delete[] pd;
#include <iostream>
using namespace std;
int main()
{
int data=10;
int *pi;
pi=new int(123);
cout << "*pi=" << *pi << endl;
delete pi;
cout << "*pi=" << *pi << endl;
double *pd=new double[5];
pd[0]=100;
cout << "pi[0]=" << pd[0] << endl;
*(pd+0)=100;
cout << "*(pd+0)=" << *(pd+0) << endl;
delete[] pd;
}