Go语言 之延迟调用defer
// 延迟调用defer project main.go package main import ( "fmt" "test" ) func f1() (r int) { //延迟调用+匿名函数 defer func() { r++ }() r = 0 return } func double(x int) int { fmt.Println("double") return x + x } func tal(x int) (r int) { defer func() { fmt.Println("func") r += x }() fmt.Println("tal") return double(x) } func main() { fmt.Println(tal(3)) i := f1() fmt.Print(i) TestA() }