Array — fixed-length, value-type, length in type. Slice — dynamic reference type backed by array.
Arrays are copied on assignment. Useful as map keys and for small fixed buffers.
1arr := [3]int{1, 2, 3}2copy := arr // full copy3copy[0] = 994fmt.Println(arr[0]) // 1 — unchanged
Slices share backing memory. Mutations propagate. append may reallocate.
1xs := []int{1, 2, 3, 4}2sub := xs[1:3] // shares array3sub[0] = 2004fmt.Println(xs[1]) // 200 — shared
When to use:
Common mistakes:
append result.==.