切片ik通过索引访问,然后为每个map分配内存;

切片jk通过获得切片内每个元素的拷贝来分配内存,并未成功为切片内每个map分配内存,使用时赋值也就失败了

 1 package main
 2 
 3 import fmt
 4 
 5 func main(){
 6         ik := make([]map[int]int,5)
 7         for i := range ik {
 8                 ik[i]=make(map[int]int,1)
 9                 ik[i][i]=i
10         }
11         fmt.Printf("value of ik :%v\n",ik)
12 
13         jk := make([]map[int]int,5)
14         for i,va := range jk {
15                 va = make(map[int]int,1)
16                 va[i]=i
17         }
18         fmt.Printf("value of jk :%v\n",jk)
19 }