How to link two Int variables?

Perhaps a demonstration will be clearest:

julia> a = Ref(42)
Base.RefValue{Int64}(42)

julia> b = a
Base.RefValue{Int64}(42)

julia> a[] = 69
69

julia> a
Base.RefValue{Int64}(69)

julia> b[]
69

julia> b
Base.RefValue{Int64}(69)

julia> a === b
true

An important bit to note is that a Ref needs to be deReferenced to get the value using the b[] notation.

6 Likes