关于数组和切片的基础复习

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])
}
}

 

posted @ 2024-04-30 17:17  飞雪飘鸿  阅读(3)  评论(0编辑  收藏  举报
https://damo.alibaba.com/ https://tianchi.aliyun.com/course?spm=5176.21206777.J_3941670930.5.87dc17c9BZNvLL