# Primitive and Composite? Types

**URL:** <https://discourse.julialang.org/t/primitive-and-composite-types/19076>\
**Category:** New to Julia\
**Created:** [December 28, 2018, 8:41pm UTC](https://discourse.julialang.org/t/primitive-and-composite-types/19076 "2018-12-28T20:41:00Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [December 29, 2018, 11:07pm UTC](https://discourse.julialang.org/t/primitive-and-composite-types/19076/7 "2018-12-29T23:07:15Z")

</div>

> [@iwelch](#):
>
> julia\> ascalar= 12; bscalar= ascalar; bscalar= 99; ascalar  
> 12
> 
> If the scalar contents had been stored at a pointed-to destination (like an array, dict, struct, etc.), then ascalar would also have turned into 99.

Not so–assignment _never_ changes any object. It just attaches a label to some existing value:

```julia
julia> a = [12]; b = a; b = [99]; a
1-element Array{Int64,1}:
 12

```

The fact that the label `b` was previously attached to the same value as `a` is of no consequence.

Of course, `b .= [99]` does mutate `a` as well, but that’s not assignment. Instead, it is roughly equivalent to: `broadcast!(b, identity, [99])`, which mutates the value to which the label `b` is attached. If that value is the same value to which the label `a` was attached, then you will see the same modification to `a`.

This gets to one of the nicest points about Julia (as opposed to, say, C++), which is that assignments and function arguments always work in the same way for every value. While the compiler _may_ copy values passed into functions, it will only do so for completely immutable values, so there is no practical reason to worry about whether a copy has happened or not. Thus you can write your code without having to worry about whether a value might accidentally be copied. Likewise, there is no need to worry about whether `a = b` creates an “alias” or a “copy” depending on the types of `a` or `b`. All assignments behave in exactly the same way: attaching a label to a value, nothing more.

---

_[View the full topic](https://discourse.julialang.org/t/primitive-and-composite-types/19076)._
