Why the variable's value does not change?

a = 200000

function TestAdd(a::Ref{Int64})

println("Before add $(a[ ])")

a[]+= 10

println("After add $(a[])")

end

TestAdd(Ref(a))

println(a)

Result as below :

Before add 200000
After add 200010
200000

Try

a = Ref(20000)
TestAdd(a)
println(a[]) 

Ref(a) has nothing to do with a, it creates a reference to the value of a not to the variable a.

2 Likes

Works, thanks