关于数组和切片的基础复习
package main import ( "fmt" ) func main() { arr:=make([]int, 3,5) arr[0],arr[1],arr[2]=2,7,9 brr:=append(arr,8) fmt.Printf("%d %d\n",len(arr),len(brr)) fmt.Printf("%d %d\n",cap(arr),cap(brr)) }
package main import ( "fmt" ) func main() { arr:=make([]int, 3,5) arr[0],arr[1],arr[2]=2,7,9 for i,ele:=range arr{ fmt.Println("%p %p %d\n",&ele,&arr[i],ele,arr[i]) } }