21. Slices
A window into an array!
Slice Type
Declaring slice
func printSlice(s []string) {
fmt.Printf("size: %v, capacity:%v,value:%v\n",
len(s), cap(s), s)
}
func main() {
// declaring slice
var names []string
printSlice(names)
//output size: 0, capacity:0,value:[]
}var a [5]int
var s []intCreating slice
Accessing slice elements
Zero values
Slice literals
Slice from an existing array
Nil and empty slice
Iterating over slice
Type of slice and comparison
Append
GitHub Code
Blog Posts
Videos
Last updated