Go编程笔记(14)

package main

import (
	"fmt"
)

func main() {
	f := closure(10)
	fmt.Println(f(1))
	fmt.Println(f(2))
}

func closure(x int) func(int) int {
	fmt.Printf("%p\n", &x)
	return func(y int) int {
		fmt.Printf("%p\n", &x)
		return x + y
	}
}

输出结果:

	0x1f2100e0
	0x1f2100e0
	11
	0x1f2100e0
	12


你可能感兴趣的:(Go编程笔记(14))