![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 package main 2 3 import ( 4 "fmt" 5 //"net/http" 6 ) 7 8 func modifyMap(s map[string]interface{}) { 9 s["a"]="a" 10 } 11 func modifyArray(a [5]int) { 12 a[2]=100 13 } 14 func modifySlice(b []int) { 15 b[0]=0 16 } 17 func modifyChannels(ch chan int) { 18 ch<-2; 19 } 20 func main() { 21 s := make(map[string]interface{}) 22 s["a"]="b" 23 fmt.Println(s); 24 modifyMap(s); 25 fmt.Println(s); 26 a := [5]int{1,2,3,4,5} 27 fmt.Println(a); 28 modifyArray(a) 29 fmt.Println(a); 30 b := []int{1,2,3,4,5} 31 fmt.Println(b); 32 modifySlice(b); 33 fmt.Println(b); 34 ch :=make(chan int,10) 35 fmt.Println(len(ch)); 36 modifyChannels(ch) 37 fmt.Println(len(ch)); 38 }
map[a:b] map[a:a] [1 2 3 4 5] [1 2 3 4 5] [1 2 3 4 5] [0 2 3 4 5] 0 1
由结果可知除了数组是传值,map、slice、chan都是传引用