今天学习内存管理,申请用new,释放用delete,申请后要检验是否成功,归还时注意数组加方框,做了个练习
明日复习看过的视频
#include<iostream>
#include<stdlib.h>
using namespace std;
#include<stdlib.h>
using namespace std;
int main(void)
{
int*p=new int[1000];
if(NULL==p)
{
system("pause");
return 0;
}
p[0]=10;
p[1]=50;
p[15]=99;
cout<<p[0]<<"."<<p[1]<<","<<p[15]<<endl;
delete []p;
p=NULL;
system("pause");
return 0;
}
{
int*p=new int[1000];
if(NULL==p)
{
system("pause");
return 0;
}
p[0]=10;
p[1]=50;
p[15]=99;
cout<<p[0]<<"."<<p[1]<<","<<p[15]<<endl;
delete []p;
p=NULL;
system("pause");
return 0;
}