# Mutable struct pitfall

**URL:** <https://discourse.julialang.org/t/mutable-struct-pitfall/44996>\
**Category:** General Usage\
**Created:** [August 15, 2020, 3:14pm UTC](https://discourse.julialang.org/t/mutable-struct-pitfall/44996 "2020-08-15T15:14:36Z")\
**Posts on this page:** 1\
**Showing post:** 10

<div class="post-metadata">

**Author:** ![Henrique\_Becker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrique_becker/32/15443_2.png) [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)\
**Post date:** [August 15, 2020, 10:57pm UTC](https://discourse.julialang.org/t/mutable-struct-pitfall/44996/10 "2020-08-15T22:57:24Z")

</div>

> [@j2b2](#):
>
> I didn’t see the keyword `struct` outside the C language, and in this case assignment is a copy.

Fair enough. I think Java has similar behavior but they use the keyword `class` instead. If you want to think in terms of C `struct`s, maybe the most sane analogy is that the problem is not the `struct` itself (mutable or immutable), but that all variables in Julia are NOT names of positions of memory, but instead, names of pointers to the memory. So, if your swap two variables i.e., `a, b = b, a` you just swap pointers instead (often you do not even pay the price of a pointer swap, the compiler elides this).

This is the best I can do using concepts of C, the truly best would be learning how Julia has bindings and not variables. @yuyichao has been answering [this question for years](https://discourse.julialang.org/t/variable-binding-re-assignment-argument-passing-let-scope/16840/5). If they give a reference (maybe to a post of them), I will always link it whenever I see a variation of this question.

---

_[View the full topic](https://discourse.julialang.org/t/mutable-struct-pitfall/44996)._
