go语言——defer
2018-12-07 本文已影响0人
mihope
defer
func f3() (r int) {
r = 1
defer func(r int) {
r = r + 1
fmt.Println("r=", r)
}(r)
r = 99
return
}
//返回结果:99,打印:2
func f4() (r int) {
r = 1
defer func(r *int) {
*r = *r + 1
fmt.Println("*r", *r)
}(&r)
r = 99
return
}
//返回结果:100,打印:100