这是我的简单代码 arrayfunc()应该将一些数字存储在一个数组中,并将此数组的指针 返回到将要打印数组内容的主函数 我的代码有什么问题? 它只返回指向数组的第一个元素的指针 任何帮助将不胜感激。 在此先感谢。如何返回指向C++数组的指针?
#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'指针数组,而不是一个指向整数数组。 http://stackoverflow.com/questions/859634/c-pointer-to-array-array-of-pointers-disambiguation – 2011-12-25 13:10:08