import (
"fmt"
)
func main() {
var x []int = []int{1, 2, 3, 4, 5}
var s []int = x[1:3]
fmt.Println(s)
fmt.Println(s[:cap(s)])
b := append(s, 6)
fmt.Println(b)
fmt.Println(b[:cap(b)])
fmt.Println(s[:cap(s)])
a := make([]int, 5)
fmt.Println(a)
}
//cmd
C:\Users\bob\golang1>go run tutorial.go
[2 3]
[2 3 4 5]
[2 3 6]
[2 3 6 5]
[2 3 6 5]
[0 0 0 0 0]
reference:
No comments:
Post a Comment