Go语言 之指针作为函数参数
package main import ( "fmt" ) func swap01(a, b int) { a, b = b, a fmt.Printf("swap01 a = %d, b = %d\n", a, b) } func swap02(x, y *int) { *x, *y = *y, *x } func main() { a := 10 b := 20 //swap01(a, b) //值传递(传值) swap02(&a, &b) //地址传递(传引用) fmt.Printf("a = %d, b = %d\n", a, b) }