概述

  • & 取地址
    • 取值

swap

  1. package main
  2. import "fmt"
  3. func swap(a *int,b*int){
  4. t:=*a
  5. *a = *b
  6. *b =t
  7. }
  8. func main() {
  9. a,b :=10,20
  10. fmt.Println("a=",a,"b=",b)
  11. swap(&a,&b)
  12. fmt.Println("a=",a,"b=",b)
  13. }
  1. a= 10 b= 20
  2. a= 20 b= 10