指针
作者:互联网
指针
package main
import "fmt"
/*
func swap(a int ,b int) {
var temp int
temp = a
a = b
b = temp
}
*/
func swap(pa *int, pb *int) {
var temp int
temp = *pa //temp = main::a
*pa = *pb // main::a = main::b
*pb = temp // main::b = temp
}
func main() {
var a int = 10
var b int = 20
swap(&a, &b)
fmt.Println("a = ", a, " b = ", b)
var p *int
p = &a
fmt.Println(&a)
fmt.Println(p)
var pp **int //二级指针
pp = &p
fmt.Println(&p)
fmt.Println(pp)
}
标签:temp,int,fmt,Println,var,main,指针 来源: https://www.cnblogs.com/suehoo/p/16632565.html