Is it possible to change the contents of a vector by means of a pointer? Of course I am aware of the following:
julia> v = zeros(6);
julia> p = v
6-element Array{Float64,1}:
0.0
0.0
0.0
0.0
0.0
0.0
julia> p[1] = 10
10
julia> v
6-element Array{Float64,1}:
10.0
0.0
0.0
0.0
0.0
0.0
But what I want is to point to a different position than the first one. For example, I realized I can do the following, but I do not know if this is the correct approach:
julia> v = zeros(6);
julia> p = Ref(v)
Base.RefValue{Array{Float64,1}}([0.0, 0.0, 0.0, 0.0, 0.0, 0.0])
julia> p[][1] = 1
1
julia> p[][6] = 6
6
julia> v
6-element Array{Float64,1}:
1.0
0.0
0.0
0.0
0.0
6.0
Then, what happens if I want to point p
to a different position than the first one of v
. Is that even possible? In C would be something like:
p = &v[3];
p[2] = 1.0 //changes v
On the other hand, when performing the following instruction
julia> p = v[1:3]
julia> p[1] = 2
2
julia> v
6-element Array{Float64,1}:
1.0
0.0
0.0
0.0
0.0
6.0
I am copying v
values to a new allocated vector p
, right?