title: Why method take struct pointer as input can modify its field value meanwhile a method take struct as input can't?
body: <p>I'm study learning golang recently. And today I encounter a phenomenon which confused me.</p>
  <p>Below is my code snippet:</p>
  <pre><code>package main // what does package main mean?
  
  import (
      &quot;strings&quot;
  )
  
  type Queue struct {
      Name string
  }
  
  func NewQueue(name string) Queue {
      return Queue{name}
  }
  
  func (q Queue) MagicMethod(word string) {
      str_list := []string {q.Name, word}
      new_str := strings.Join(str_list[:], &quot;&quot;)
      println(&quot;MagicMethod-new_str:&quot;, new_str)
      q.Name = new_str
      println(&quot;MagicMethod-Queue.Name:&quot;, q.Name)
  }
  
  func main() {
      x := NewQueue(&quot;xxx&quot;)
      x.MagicMethod(&quot;y&quot;)
      println(&quot;main-Queue.Name:&quot;, x.Name)
      x.MagicMethod(&quot;z&quot;)
      println(&quot;main-Queue.Name:&quot;, x.Name)
  }
  
  </code></pre>
  <p>My intention is to build a method for Queue, which can append new string to its Name. But this code didn't realize my intention. Its output is:</p>
  <pre><code>MagicMethod-new_str: xxxy
  MagicMethod-Queue.Name: xxxy
  main-Queue.Name: xxx
  MagicMethod-new_str: xxxz
  MagicMethod-Queue.Name: xxxz
  main-Queue.Name: xxx
  </code></pre>
  <p>Which confused me, from the output I can see that inside the MagicMethod, the value for q.Name has changed corresponds to the input arg. But it didn't affect the Name of outside Queue - x.</p>
  <p>I did some experiment then and found if I change <code>func (q Queue) MagicMethod(word string)</code> to <code>func (q *Queue) MagicMethod(word string)</code>， I can get the result I preferred, which is:</p>
  <pre><code>MagicMethod-new_str: xxxy
  MagicMethod-Queue.Name: xxxy
  main-Queue.Name: xxxy
  MagicMethod-new_str: xxxyz
  MagicMethod-Queue.Name: xxxyz
  main-Queue.Name: xxxyz
  </code></pre>
  <p>But still I don't know the mechanism why this works.
  So, why did the first method which takes <code>q Queue</code> as input does changed the Name field inside the MagicMethod but didn't change it outside of the method? What's the mechanism of it?</p>