# Why the variable's value does not change?

**URL:** <https://discourse.julialang.org/t/why-the-variables-value-does-not-change/78120>\
**Category:** General Usage\
**Tags:** question\
**Created:** [March 19, 2022, 4:20am UTC](https://discourse.julialang.org/t/why-the-variables-value-does-not-change/78120 "2022-03-19T04:20:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![PoleZhang](https://avatars.discourse-cdn.com/v4/letter/p/c4cdca/32.png) [@PoleZhang](https://discourse.julialang.org/u/PoleZhang)\
**Post date:** [March 19, 2022, 4:20am UTC](https://discourse.julialang.org/t/why-the-variables-value-does-not-change/78120/1 "2022-03-19T04:20:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)\
**Post date:** [March 19, 2022, 8:48am UTC](https://discourse.julialang.org/t/why-the-variables-value-does-not-change/78120/2 "2022-03-19T08:48:07Z")

</div>

Try

```julia
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`.

---

<div class="post-metadata">

**Author:** ![PoleZhang](https://avatars.discourse-cdn.com/v4/letter/p/c4cdca/32.png) [@PoleZhang](https://discourse.julialang.org/u/PoleZhang)\
**Post date:** [March 19, 2022, 9:01am UTC](https://discourse.julialang.org/t/why-the-variables-value-does-not-change/78120/3 "2022-03-19T09:01:42Z")

</div>

Works, thanks
