有一个小问题!

来源:百度知道 编辑:UC知道 时间:2024/06/20 05:57:20
#include <iostream.h>
#include <stdlib.h>
void main()
{
int i;
int number;
cout<<"Please input number:";
cin>>number;
double *ptr=new double[number];//声明指针变量ptr,使其指向由new创建数组对象的起始地址
if(ptr==NULL)
{
cout<<"can't allocate memory !\n";
exit(1);
}
for(i=0;i<number;i++)
cin>>ptr[i];
for(i=0;i<number;i++)
cout<<ptr[i]<<" ";
cout<<endl;
for(i=number-1;i>=0;i--)
cout<<ptr[i]<<" ";
cout<<endl;
delete []ptr;//删除堆对象
}
这句话中
if(ptr==NULL)
{
cout<<"can't allocate memory !\n";
exit(1);
}
的exit(1);是什么意思.有什么作用!

double *ptr=new double[number];//声明指针变量ptr,使其指向由new创建数组对象的起始地址
if(ptr==NULL) //如果没有创建成功
{
cout<<"can't allocate memory !\n";
exit(1); //退出
}

exit()函数用于退出程序。

exit(1);//退出程序,返回值为1

LS正解,通常返回0表示正常结束,返回非0表示非正常结束