An array is a reference type.  Somewhere in memory, this array is created, 
but the actual value of the variable A is just the address to this array. 
 When you say A0 = A, you're giving that same address to A0.  So you can 
use either A or A0 to look at/modify/whatever the numbers in that array. 
 However, they're working on exactly the same array.  So if you use A0 to 
access the array and modify it, you can see those changes when you use A 
because* there's only one array*.

John's answer, that you use copy(A), allows you to make two arrays.  They 
are in different spots in memory, so A and A0 are pointing to different 
arrays, and modifying one won't have any effect on the other.

--Mikayla


On Monday, June 23, 2014 11:42:48 AM UTC-5, JuliaLover wrote:
>
> Hi,
> I have a problem that when I assign value of one array to another they 
> stick to each other whenever I change either array. For example,
>
> A = [1,2,4,6]
> A0 = A
>
> then now I just want to change last value of A.
>
> A[4] =0
>
> A change to [1,2,4,0]
>
> But now "A0" also automatically updates its values, A0 also now becomes 
> [1,2,4,0].
>
> This result is not that I want. I just want to change A only, and still 
> keep A0 the same as before (i.e. A0=[1,2,4,6]). 
>
> Do you know how to deal with the problem ? 
>
> Many thanks for your help.
>

Reply via email to