see test code:
package main
import "fmt"
func main() {
i := 10
closure1 := func() {
fmt.Printf("closure, i: %d
", i)
i = 15
}
closure1()
fmt.Printf("in main, i: %d
", i)
closure2 := func(x int) {
fmt.Printf("function call, pass parameter, i: %d
", x)
}
i = 20
closure1()
closure2(i)
}
I think the output of the closure2 should be 20, but the real result is 15, i do not know why???? anybody can help me , please see my comment in my code, thanks in advance.