# What is the reason for a zero-dimensional array?

**URL:** <https://discourse.julialang.org/t/what-is-the-reason-for-a-zero-dimensional-array/7175>\
**Category:** General Usage\
**Tags:** array\
**Created:** [November 20, 2017, 2:01am UTC](https://discourse.julialang.org/t/what-is-the-reason-for-a-zero-dimensional-array/7175 "2017-11-20T02:01:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![anon94023334](https://avatars.discourse-cdn.com/v4/letter/a/e274bd/32.png) [@anon94023334](https://discourse.julialang.org/u/anon94023334)\
**Post date:** [November 20, 2017, 2:01am UTC](https://discourse.julialang.org/t/what-is-the-reason-for-a-zero-dimensional-array/7175/1 "2017-11-20T02:01:43Z")

</div>

Consider:

```julia
foo(v) = [x + 5 for x in v]

```

I think that in most cases if `foo` is called with a scalar, one wants a scalar value back, equivalent to `foo(v) = v + 5`. However, this function results in

```julia
julia> foo(5)
0-dimensional Array{Int64,0}:
10

```

which is type stable when `v` is an array, but not exactly what we want.

Is there a reason that a zero-dimensional array exists? How is it different from a scalar?

---

<div class="post-metadata">

**Author:** ![Stephen\_Vavasis](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stephen_vavasis/32/3389_2.png) [@Stephen\_Vavasis](https://discourse.julialang.org/u/Stephen_Vavasis)\
**Post date:** [November 20, 2017, 2:57am UTC](https://discourse.julialang.org/t/what-is-the-reason-for-a-zero-dimensional-array/7175/2 "2017-11-20T02:57:59Z")

</div>

0-dimensional arrays can be used to pass scalars to a function via “call-by-reference.” E.g.

```julia
   a = zeros()
   a[] = 7
   b = 7
   modify!(a,b) # changes a but not b

   function modify!(a,b)
     a[] = 9
     b = 9
   end

```

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [November 20, 2017, 8:23am UTC](https://discourse.julialang.org/t/what-is-the-reason-for-a-zero-dimensional-array/7175/3 "2017-11-20T08:23:49Z")

</div>

> [@Stephen\_Vavasis](#):
>
> 0-dimensional arrays can be used to pass scalars to a function via “call-by-reference.”

True, but perhaps `Ref` communicates this intent more clearly.
