title: Meaning of the ampersand '&' and star '*' symbols in Rust
body: <p>Despite thoroughly reading the documentation, I'm rather confused about the meaning of the <code>&amp;</code> and <code>*</code> symbol in Rust, and more generally about what is a Rust reference exactly.</p>
  
  <p>In this example, it seems to be similar to a C++ reference (that is, an address that is automatically dereferenced when used):</p>
  
  <pre><code>fn main() {
      let c: i32 = 5;
      let rc = &amp;c;
      let next = rc + 1;
      println!("{}", next); // 6
  }
  </code></pre>
  
  <p>However, the following code works exactly the same:</p>
  
  <pre><code>fn main() {
      let c: i32 = 5;
      let rc = &amp;c;
      let next = *rc + 1;
      println!("{}", next); // 6
  }
  </code></pre>
  
  <p>Using <code>*</code> to dereference a reference wouldn't be correct in C++. So I'd like to understand why this is correct in Rust.</p>
  
  <p>My understanding so far, is that, inserting <code>*</code> in front of a Rust reference dereferences it, but the <code>*</code> is implicitly inserted anyway so you don't need to add it (while in C++, it's implicitly inserted and if you insert it you get a compilation error).</p>
  
  <p>However, something like this doesn't compile:</p>
  
  <pre><code>fn main() {
      let mut c: i32 = 5;
      let mut next: i32 = 0;
      {
          let rc = &amp;mut c;
          next = rc + 1;
      }
      println!("{}", next);
  }
  </code></pre>
  
  <pre class="lang-none prettyprint-override"><code>error[E0369]: binary operation `+` cannot be applied to type `&amp;mut i32`
   --&gt; src/main.rs:6:16
    |
  6 |         next = rc + 1;
    |                ^^^^^^
    |
    = note: this is a reference to a type that `+` can be applied to; you need to dereference this variable once for this operation to work
    = note: an implementation of `std::ops::Add` might be missing for `&amp;mut i32`
  </code></pre>
  
  <p>But this works:</p>
  
  <pre><code>fn main() {
      let mut c: i32 = 5;
      let mut next: i32 = 0;
      {
          let rc = &amp;mut c;
          next = *rc + 1;
      }
      println!("{}", next);  // 6
  }
  </code></pre>
  
  <p>It seems that implicit dereferencing (a la C++) is correct for immutable references, but not for mutable references. Why is this?</p>