Search code examples
godefault-value

How is the value of dx and dy 256 in tour.golang.org/moretypes/18?


I've been learning golang using tour.golang.org.

In the following code, when I print the value of dx and dy which are both of type integer, the value comes out to be 256.

package main

import ("golang.org/x/tour/pic"
        "fmt"
        )

func Pic(dx, dy int) [][]uint8 {
    fmt.Printf("%T\n",dx)
    fmt.Println(dx)
    
    ret := make([][]uint8, dy)
    for i := range(ret){
        ret[i] = make([]uint8, dx)
    }
    return ret
}

func main() {
    pic.Show(Pic)
}

How does the golang compiler know the value of those two integers declared in the function Pic?


Solution

  • From main, you're calling pic.Show with your function, Pic. Looking at the source code for pic.Show, it calls the function it's given with 256 for each dimension.