title: When should I initialize Golang variables
body: <p>There are some kind of variables in Golang:</p>
  
  <ol>
  <li>global variable: <code>var a int</code></li>
  <li>local variable: <code>func hello() { var a int }</code></li>
  <li>return variable: <code>func hello() (a int) {}</code></li>
  </ol>
  
  <p>Golang sometimes will auto-init some variables,<br>
  but I don't know when and why? It confused me.</p>
  
  <p>Example:</p>
  
  <pre><code>type User struct {
    Name string `json:"name"`
    Age  int    `json:"age"`
  }
  
  func foo(bts []byte) {
    var a User
    err := json.Unmarshal(bts, &amp;a)  // It's ok
  }
  
  func bar(bts []byte) (a *User) {
    err := json.Unmarshal(bts, a) // It will crash
  }
  </code></pre>
  
  <p>which one should I have to initialize before use?</p>