← BYTES
Go·Starter·Ref: 10.1.6
What is the key difference between a Go array and a Go slice?
Have a question about this video? Mention reference 10.1.6 when you contact us.
a.Arrays can only hold numbers; slices can hold any type
b.Slices are always faster than arrays for every operation
c.An array's length is part of its type and fixed at compile time; a slice is a dynamically-sized, flexible view over an underlying array
d.There is no real difference; slice is just another name for array
In Go, [5]int and [10]int are genuinely different, incompatible types because the length is encoded in the array type itself and fixed. A slice, by contrast, is a small descriptor (pointer, length, capacity) over a backing array and can grow via append -- which is why slices, not arrays, are the idiomatic everyday collection type in Go.
Find this on YouTube & Instagram
Every BYTES video is tagged with its reference number and topic — search any of these on YouTube or Instagram to find this one:
#BYTES#BYTES1016#Go