package main import ( "fmt" ) func main() { numbers := []int{1, 2, 3, 4, 5} fmt.Println("Size of the slice:", cap(numbers)) }
Size of the slice: 5
package main import ( "fmt" ) func main() { names := []string{} names = append(names, "Alice", "Bob") fmt.Println("Size of the slice:", cap(names)) }
Size of the slice: 2Overall, the github.com/mumax3/data package library in Go provides convenient functions to handle slices, including determining their size using cap().