Senior
What is the length of a nil slice in Go?
sobes.tech AI
Answer from AI
In Go, the length of a nil slice is 0. A nil slice is a slice that does not point to any array and has the value nil. The functions len() and cap() for a nil slice return 0.
Example:
var s []int // s == nil
fmt.Println(len(s)) // 0
fmt.Println(cap(s)) // 0
Thus, a nil slice behaves like an empty slice with length 0.