# Pass array value by reference in function definition

**URL:** https://community.freefem.org/t/pass-array-value-by-reference-in-function-definition/2546
**Category:** General Discussion
**Created:** [June 16, 2023, 10:08am UTC](https://community.freefem.org/t/pass-array-value-by-reference-in-function-definition/2546 "2023-06-16T10:08:19Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![m.lbolok](https://avatars.discourse-cdn.com/v4/letter/m/d2c977/32.png) [@m.lbolok](https://community.freefem.org/u/m.lbolok)
#### Post date: [June 16, 2023, 10:08am UTC](https://community.freefem.org/t/pass-array-value-by-reference-in-function-definition/2546/1 "2023-06-16T10:08:19Z")

</div>

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++ ?

---

<div class="post-metadata">

### Author: ![jbl](https://avatars.discourse-cdn.com/v4/letter/j/e47c2d/32.png) [@jbl](https://community.freefem.org/u/jbl)
#### Post date: [June 16, 2023, 10:22am UTC](https://community.freefem.org/t/pass-array-value-by-reference-in-function-definition/2546/2 "2023-06-16T10:22:39Z")

</div>

Hi,

I’m not sure I understand what you want.

```auto
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?

---

<div class="post-metadata">

### Author: ![m.lbolok](https://avatars.discourse-cdn.com/v4/letter/m/d2c977/32.png) [@m.lbolok](https://community.freefem.org/u/m.lbolok)
#### Post date: [June 16, 2023, 10:32am UTC](https://community.freefem.org/t/pass-array-value-by-reference-in-function-definition/2546/3 "2023-06-16T10:32:43Z")

</div>

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