在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
1、切片和底层数组关系 示例: package main //必须有个main包 import "fmt" func main() { a := []int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9} //新切片 s1 := a[2:5] //从a[2]开始,取3个元素 s1[1] = 666 fmt.Println("s1 = ", s1) //[2 3 4] fmt.Println("a = ", a) //[2 666 4] //另外新切片 s2 := s1[2:7] s2[2] = 777 fmt.Println("s2 = ", s2) //[4 5 777 7 8] fmt.Println("a = ", a) //[0 1 2 666 4 5 777 7 8 9] } 执行结果: s1 = [2 666 4] a = [0 1 2 666 4 5 6 7 8 9] s2 = [4 5 777 7 8] a = [0 1 2 666 4 5 777 7 8 9]
|
请发表评论