title: Please explain if golang types pass by value
body: <p>I'm trying to make a very simple program that modifies arrays, but ran across some interesting behavior if I converted them to types. <a href="https://play.golang.org/p/KC7mqmHuLw" rel="noreferrer">https://play.golang.org/p/KC7mqmHuLw</a> It appears that if I have an array go passes by reference, but if I have a type then go passes by value.  Is this correct?</p>
  
  <p>I have two variables b and c, both are arrays of 3 integers, but c is of type cT, in every other respect they should be identical.  I can assign values as <code>b[0]=-1</code> and <code>c[0]=-1</code>, but if I pass those arrays as parameters to a function they act very differently.</p>
  
  <p>The output of the program is:</p>
  
  <blockquote>
    <p>before b: [1 2 3]</p>
    
    <p>before c: [1 2 3]</p>
    
    <p>*after b: [-1 2 0]</p>
    
    <p>*after c: [-1 2 3]</p>
    
    <p>*what? c: [-1 2 0]</p>
  </blockquote>
  
  <p>My initial assumption is that the lines "after b" and "after c" should have been the same.  Am I doing something incorrectly or am I correct about types passing to functions by value (ie. creating copy of the variable before passing to the function)?</p>
  
  <pre><code>package main
  
  import "fmt"
  
  type cT [3]int
  
  func main() {
      b := []int{1, 2, 3}
      c := cT{1, 2, 3}
  
      fmt.Println("before b:", b)
      fmt.Println("before c:", c)
  
      b[0] = -1
      c[0] = -1
      mangleB(b) // ignore return value
      mangleC(c) // ignore return value
  
      fmt.Println("*after b:", b)
      fmt.Println("*after c:", c)
  
      c = mangleC(c)    
      fmt.Println("*what? c:", c)    
  }
  
  func mangleB(row []int) []int {
      row[2] = 0
      return row
  }
  
  func mangleC(row cT) cT{
      row[2] = 0
      return row
  }
  </code></pre>