一个函数中有可能返回一个数组或NULL;然后需要在main函数中把数组或NULL取出来并打印,这个类型转换时比较容易出错,需要注意
#include <iostream>
using namespace std;int value=0;
int data[3]={0};
int *test(void)
{
if(value)
{
data[0]=0;
data[1]=1;
data[2]=2;
return data;
}
else
return NULL;
}
void main()
{
int *a;
a=test();
if(a==NULL)
cout<<NULL<<endl;
else
{
for(int i=0;i<3;i++)
{
cout<<*a++<<endl;
}
}
}