【发布时间】:2011-12-25 13:00:23
【问题描述】:
这是我的简单代码 arrayfunc() 应该将一些数字存储在一个数组中,并返回这个数组的指针 到将打印数组内容的主函数 我的代码有什么问题? 它只返回指向数组第一个元素的指针 任何帮助将不胜感激。 提前致谢。
#include <iostream>
using namespace std;
//The definition of the function should remain the same
int* arrayfunc()
{
int *array[10];
array[0] =new int;
array[1] =new int;
array[2] =new int;
array[3] =new int;
*array[0]=10;
*array[1]=11;
*array[2]=12;
*array[3]=13;
return *array;
}
int main()
{
for(int i=0;i<4;i++)
cout<<*(arrayfunc()+i)<<endl;
return 0;
}
【问题讨论】:
-
这里有一个
int指针数组,而不是指向整数数组的指针。 stackoverflow.com/questions/859634/…