// example1.go

package main


func main() {
 var y int // BAD: y escapes
 func(p *int, x int) {
 *p = x
 }(&y, 42)
}

example1.go  y escape to the heap

// example2.go

package main

func main() {
 var y int
 func(x int) {
 y = x
 }(42)
}

  example2.go y is not escaped and why ??

// example3.go

package main

func main() {
 a := 100
 y := &a
 func(x int) {
 *y = x
 }(42)
}

 example3.go y is not escaped and why ??

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to