查看完整版本: function中可以return一个数组么?

win3323 2007-9-12 11:33

function中可以return一个数组么?

如题function中可以return一个数组么?
如果可以该怎么写,举个例子好么?

在帮助中写有这么一段:
[color=Blue]The return value of a function can be one of the following:
char (signed and unsigned)
string (equivalent to C char*)
short (signed and unsigned)
int (signed and unsigned)
long (signed and unsigned)
float
double[/color]
是不是不能把数组做为返回值?

[color=Magenta]我现在想返回多个数值,该如何做呢?[/color]
比如:
  function bac(in c)

我想让它返回六个整数数值,具体的可以怎么做?

[color=Red]谁帮助指导下。谢谢拉。。。。。。。。。。。。。。。。。。[/color]

lantianwei 2007-9-12 12:20

function bac(in c,out result[])
{
result[1]=c+1;
result[2]=c+2;
result[3]=c+3;
result[4]=c+4;
result[5]=c+5;
result[6]=c+6;
}
调用:
bac(23,res);
for(i=1;i<7;i++)
printf()res[i];

你试下,估计可以,如果有错,你把res写成res[]

hujh 2007-9-12 14:13

bu cuo

不错

win3323 2007-9-12 15:18

谢谢 lantianwei 。还有点问题自己改


真失败。。。不小心我auto了.返回的都没东西,开头我也房主的那样写法老是没东西。笔误..
现在搞定了.

[[i] 本帖最后由 win3323 于 2007-9-12 15:56 编辑 [/i]]
页: [1]
查看完整版本: function中可以return一个数组么?