some try on func swap about & and *


import "fmt"

func swap(x,y *int ) {
//x ,y = y,x //fault

/*
t := *x
*x = *y
*y = t
*/ //true

//*x , *y = *y ,*x //true

//x , y = y , x //fault

}
func pri(a,b int) {
fmt.Println(a)
fmt.Println(b)
}
func main () {

var a int = 1
var b int = 2
pri(a,b)
swap(&a,&b)
pri(a,b)
}

猜你喜欢

转载自www.cnblogs.com/qiaoyanlin/p/11994538.html