package main
import "fmt"
func swap(a,b *int){
fmt.Printf("01>>&a=%p,&b=%p\n",a,b)
a,b = b,a
fmt.Printf("02>>&a=%p,&b=%p\n",a,b)
fmt.Printf("03>>&a=%d,&b=%d\n",*a,*b)
}
func main() {
var a,b int = 1,2
fmt.Println("00>>",a,b)
//fmt.Printf("01>>&a=%p,&b=%p\n",&a,&b)
swap(&a,&b )
fmt.Println(a,b)
fmt.Printf("05>>&a=%p,&b=%p\n",&a,&b)
}
输出:
00>> 1 2
01>>&a=0xc0000120b0,&b=0xc0000120b8
02>>&a=0xc0000120b8,&b=0xc0000120b0
03>>&a=2,&b=1
1 2
05>>&a=0xc0000120b0,&b=0xc0000120b8