# Why does append! apply to both vectors

**URL:** <https://discourse.julialang.org/t/why-does-append-apply-to-both-vectors/5475>\
**Category:** New to Julia\
**Created:** [August 20, 2017, 6:20pm UTC](https://discourse.julialang.org/t/why-does-append-apply-to-both-vectors/5475 "2017-08-20T18:20:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![phymics](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/phymics/32/2894_2.png) [@phymics](https://discourse.julialang.org/u/phymics)\
**Post date:** [August 20, 2017, 6:20pm UTC](https://discourse.julialang.org/t/why-does-append-apply-to-both-vectors/5475/1 "2017-08-20T18:20:35Z")

</div>

Dear Julia Community,

I struggle to understand the append!-function and I would much appreciate any help:) Consider the following minimal example

```julia
x_0 = [1;1]
x_1 = x_0
x_2 = x_0
append!(x_1,x_2)

```

As a result all three vectors have now a length of 4. However, the example

```julia
x_0 = [1;1]
x_1 = [1;1]
x_2 = x_0
append!(x_1,x_2)

```

creates the expected result: `x_1` has length 4, while the other two have a length of 2.

Thank you very much for your help!

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [August 20, 2017, 6:34pm UTC](https://discourse.julialang.org/t/why-does-append-apply-to-both-vectors/5475/2 "2017-08-20T18:34:35Z")

</div>

Assignment to an untyped variable never make a copy so `x_0`, `x_1` and `x_2` are all the same array (in the first case. Or `x_2` and `x_0` in the second case).

---

<div class="post-metadata">

**Author:** ![phymics](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/phymics/32/2894_2.png) [@phymics](https://discourse.julialang.org/u/phymics)\
**Post date:** [August 22, 2017, 1:50am UTC](https://discourse.julialang.org/t/why-does-append-apply-to-both-vectors/5475/3 "2017-08-22T01:50:11Z")

</div>

Thats fantastic. Thank you very much for your explanation. As a coding-novice, I find it surprising that arrays behave in such a way. Is there preferred way to create independent copies on an array? Currently, I multiply each one by 1 to get around.

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [August 22, 2017, 3:38am UTC](https://discourse.julialang.org/t/why-does-append-apply-to-both-vectors/5475/4 "2017-08-22T03:38:36Z")

</div>

`copy`
