3 ms·
No it’s not -- I just checked the language specification and it says: After slicing the array a a := [5]int{1, 2, 3, 4, 5} s := a[1:4] the slice s has type
by iainmerrick 4y ago
No it’s not -- I just checked the language specification and it says:
After slicing the array a
a := [5]int{1, 2, 3, 4, 5}
s := a[1:4]
the slice s has type []int, length 3, capacity 4
Many of us here are arguing that the default should be cap==len==3, but it’s not, it’s 4.
- Groxx 4y agoWelp. TIL. Yeah, that's much more error prone I think. It's the sort of thing that only kinda makes sense on zero-valued arrays... and even then it's dubious at best. Bleh. I'm gonna go review some old code now D: