# Hello, just interesting b is link to a?

**URL:** https://discourse.processing.org/t/hello-just-interesting-b-is-link-to-a/44376
**Category:** Beginners
**Created:** [May 3, 2024, 10:40am UTC](https://discourse.processing.org/t/hello-just-interesting-b-is-link-to-a/44376 "2024-05-03T10:40:46Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![zlfp](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/zlfp/32/19543_2.png) [@zlfp](https://discourse.processing.org/u/zlfp)
#### Post date: [May 3, 2024, 10:40am UTC](https://discourse.processing.org/t/hello-just-interesting-b-is-link-to-a/44376/1 "2024-05-03T10:40:46Z")

</div>

just interesting if we like  
do that

```auto
int[] a = {1,2,3};
int[] b = a;

```

b is link to a, or b is {1,2,3}?  
and if we redact b (if its link), we redact b or a?

anyways, thanx

---

<div class="post-metadata">

### Author: ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)
#### Post date: [May 3, 2024, 2:15pm UTC](https://discourse.processing.org/t/hello-just-interesting-b-is-link-to-a/44376/2 "2024-05-03T14:15:41Z")

</div>

The question is

> After line 2 does `b` reference the same array as `a` or does it hold a separate copy of array `a`.?

If we try this

```auto
int [] a = {1, 2, 3};
int [] b = a;
println("--- Array b ---");
printArray(b);
a[0] = 999; // change first element of array 'a'
println("--- Array b ---");
printArray(b);

```

we get the output

```---
[0] 1
[1] 2
[2] 3
--- Array b ---
[0] 999
[1] 2
[2] 3

```

This shows that there is only _ **one** _ array but it is referenced by both `a` and `b`

---

<div class="post-metadata">

### Author: ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)
#### Post date: [May 3, 2024, 2:21pm UTC](https://discourse.processing.org/t/hello-just-interesting-b-is-link-to-a/44376/3 "2024-05-03T14:21:26Z")

</div>

This shows how to make a copy

```auto
int [] a = {1, 2, 3};
int [] b = new int[3];
arrayCopy(a,b);
a[0] = 999;
println("--- Array a ---");
printArray(a);
println("--- Array b ---");
printArray(b);

```

Outputs

```auto
--- Array a ---
[0] 999
[1] 2
[2] 3
--- Array b ---
[0] 1
[1] 2
[2] 3

```

---

<div class="post-metadata">

### Author: ![zlfp](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/zlfp/32/19543_2.png) [@zlfp](https://discourse.processing.org/u/zlfp)
#### Post date: [May 3, 2024, 2:24pm UTC](https://discourse.processing.org/t/hello-just-interesting-b-is-link-to-a/44376/4 "2024-05-03T14:24:44Z")

</div>

big thanx quark  
p.s. i dont needed how to do copy of `a`
