Is there a difference between slices and arrays? Well, if there is any, it is a difference of relations. slice
depends on array
, when you declare a slice in Go you get an underlying array associated with your slice, if you have several slices of the same type they may even share storage with the underlying array.
How do you create a slice?
You can use the same facilities for declaring arrays in Go, with the optional argument for "capacity" provided:
make([]int, 50, 100)
This is the same as creating an array and slicing it:
new([100]int)[0:50]
Top comments (0)