make and Capacity
make creates slices and maps with a length and capacity. cap shows how much fits before growth.
Example
package main
import "fmt"
func main() {
s := make([]int, 2, 5)
fmt.Println(len(s), cap(s))
s = append(s, 9)
fmt.Println(s, len(s), cap(s))
}Result
2 5 [0 0 9] 3 5
Exercise
Create a slice.
([]int, 3)Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.