Pass array value by reference in function definition

Hi,

I would like to pass an array by reference in a function. I have tried this:

func real myfunc2(real a,real b,real[int] &c(2))
{
c(0)=a+b;
c(1)=a-b;
return 0.;
}

But it does not work. Is there any way to pass an array or matrix by reference in FreeFem++ ?

Hi,

I’m not sure I understand what you want.

func real myfunc2(real a,real b,real[int] &c)
{
c(0)=a+b;
c(1)=a-b;
return 0.;
}

real a = 10;
real b = 1;
real[int] c(2) ;

real Exec = myfunc2(a,b,c);
cout << c << endl;

Does this code give you what you want?

1 Like

Hi,
Yes, it is exactly what I wanted to know. Many thanks for your help.