title: difference between declaring variables with var vs without var in go
body: <p>I was having some trouble with <a href="http://tour.golang.org/#35" rel="nofollow noreferrer">step 35 in the tour of Go</a> exercise.</p>
  
  <p>Here's what my code looks like:</p>
  
  <pre><code>package main
  
  import "code.google.com/p/go-tour/pic"
  
  func Pic(dx, dy int) [][]uint8 {
      var pic = make([][]uint8, dy)
      for y := 0; y &lt; dy; y++ {
          pic[y] = make([]uint8, dx)
          for x := 0; y &lt; dx; x++ {
              pic[y][x] = uint8(x*y)
          } 
      }
      return pic
  }
  </code></pre>
  
  <p>When looking for a solution, I found <a href="https://stackoverflow.com/questions/11585008/go-tour-excerciseslices-index-out-of-range#answer-11585467">PeterSO's</a> code which works perfectly</p>
  
  <pre><code>func main() {
      pic.Show(Pic)
  }
  
  func Pic(dx, dy int) [][]uint8 {
      pixels := make([][]uint8, dy)
      for y := 0; y &lt; dy; y++ {
          pixels[y] = make([]uint8, dx)
          for x := 0; x &lt; dx; x++ {
              pixels[y][x] = uint8(x * y)
          }
      }
      return pixels
  }
  </code></pre>
  
  <p>The only difference I can see, is that I'm defining the <code>pic</code> variable using the <code>var</code> keyword whereas his code is using the <code>:=</code> assignment. Now, why does my code not work?</p>