title: Golang, change the array by pointer
body: <p>I have some arrays of different struct, and I need to change them by the same function <code>func foo(arr interface{})</code>.</p>
  
  <p>And I use the function in this way <code>foo(&amp;arrayToChange)</code></p>
  
  <p>Then I find that, I cannot change the array by pointer a <a href="https://play.golang.org/p/siC8FZ4Zry" rel="nofollow noreferrer">simple example</a> for you.</p>
  
  <pre><code>package main
  
  import (
      "fmt"
  )
  
  func A(out interface{}) {
      arr := make([]interface{}, 0)
      arr = append(arr, "foo", 2.2)
      out = &amp;arr
      B(out)
  }
  
  func B(out interface{}) {
      arr := make([]interface{}, 0)
      arr = append(arr, "bar", "foo", "anything")
      out = &amp;arr
  }
  
  func main() {
      arr := make([]interface{}, 0)
      arr = append(arr, 1, 2, 3)
      fmt.Printf("%T\n", &amp;arr)
      A(&amp;arr)
      fmt.Println(arr)
  }
  </code></pre>