package main
func main() {
println(DeferFunc1(1))
println(DeferFunc2(1))
println(DeferFunc3(1))
}
func DeferFunc1(i int) (t int) {
t = i
defer func() {
t += 3
}()
return t
}
func DeferFunc2(i int) int {
t := i
defer func() {
t += 3
}()
return t
}
func DeferFunc3(i int) (t int) {
defer func() {
t += i
}()
return
}
为什么 DeferFunc2 返回值是 1,特别不理解,我分析是4,和DeferFunc1 返回值一样啊,请大神指导一下呗
有疑问加站长微信联系(非本文作者)