return 问题
怎样return 一列数组呀?比如说return a[1],a[2],...a[n]
然后操作这个指针就行了
[此贴子已经被作者于2007-11-19 16:07:21编辑过]
[CODE]
#include <iostream>
using namespace std;
/**
The caller is responsile for freeing the memory.
*/
int* f(int n)
{
int* a = new int[n];
for(int i=0; i<n; ++i)
a[i] = n;
return a;
}
int main()
{
int n=6;
int* b = f(n);
for(int i=0; i<n; ++i)
cout<<b[i]<<" ";
cout<<endl;
delete [] b;
return 0;
}
[/CODE]
都不看别人的回复吗?