# Problem on adding two arrays

**URL:** <https://community.freefem.org/t/problem-on-adding-two-arrays/2001>\
**Category:** General Discussion\
**Created:** [September 11, 2022, 4:27am UTC](https://community.freefem.org/t/problem-on-adding-two-arrays/2001 "2022-09-11T04:27:50Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![hezl09](https://avatars.discourse-cdn.com/v4/letter/h/f07891/32.png) [@hezl09](https://community.freefem.org/u/hezl09)\
**Post date:** [September 11, 2022, 4:27am UTC](https://community.freefem.org/t/problem-on-adding-two-arrays/2001/1 "2022-09-11T04:27:50Z")

</div>

Hello everyone,  
I have a question on adding two arrays together, illustrating using the following code.

> real[int] vec1(2), vec2(2), vec3(2);  
> vec1 = 1.;  
> vec2 = 2.;  
> vec3 = 2\*(vec1+vec2);

Then the code cannot run, with problem saying “error operator \* , \<7Add\_KN\_IdE\>”. However, once I change the last sentence to the following

> vec3 = 2 \* vec1 + 2 \* vec2;

Then the code is good to run. I’m really confused about how this problem occurs. Thanks if anyone can help.

---

<div class="post-metadata">

**Author:** ![frederichecht](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/frederichecht/32/15_2.png) [@frederichecht](https://community.freefem.org/u/frederichecht)\
**Post date:** [September 20, 2022, 4:01pm UTC](https://community.freefem.org/t/problem-on-adding-two-arrays/2001/2 "2022-09-20T16:01:42Z")

</div>

The is due to c++ because you write `2*(vec1+vec2)` you need a have a temporary array  
so store de vector `(vec1+vec2)` (too expensive, so a do not code).
