What is the difference between a slice and an array in Go?

Answer

An array in Go has a fixed length that is part of its type: [5]int and [3]int are different types. Arrays are value types — assigning an array copies all its elements. A slice is a dynamic, flexible view over an underlying array described by a pointer, a length, and a capacity: []int. Slices are reference types — multiple slices can share the same backing array. Append to a slice with append(s, elem), which grows the backing array automatically when capacity is exceeded. In practice, slices are used almost exclusively; raw arrays are rare.