some try on func swap about & and *
Posted qiaoyanlin
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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)
}
以上是关于some try on func swap about & and *的主要内容,如果未能解决你的问题,请参考以下文章