title: Re-slicing slices in Golang
body: <p>I recently picked up the Go language, and now I am confused with the following code:</p>
  
  <pre><code>package main
  
  import "fmt"
  
  func main() {
      a := make([]int, 5)
      printSlice("a", a)
      b := make([]int, 0, 5)
      printSlice("b", b)
      c := b[:2]
      printSlice("c", c)
      d := c[2:5]
      printSlice("d", d)
  }
  
  func printSlice(s string, x []int) {
      fmt.Printf("%s len=%d cap=%d %v\n",
          s, len(x), cap(x), x)
  }
  </code></pre>
  
  <p>And the result:</p>
  
  <pre><code>a len=5 cap=5 [0 0 0 0 0]
  b len=0 cap=5 []
  c len=2 cap=5 [0 0] //why the capacity of c not 2 but 5 instead
  d len=3 cap=3 [0 0 0]
  </code></pre>