Array — fixed-length, value-type, length is part of the type. Slice — dynamic reference type backed by an array.
Arrays copy on assignment. This makes them safe from shared-state bugs but expensive for large sizes.
1arr := [3]int{1, 2, 3}2copy := arr // full copy3copy[0] = 994fmt.Println(arr[0]) // 1 — unchanged
Slices share backing memory. Multiple slices can reference the same array, and mutations propagate. append may reallocate.
1xs := []int{1, 2, 3, 4}2sub := xs[1:3] // shares array3sub[0] = 200 // mutates xs[1] too4xs = append(xs, 5) // may reallocate
When to use:
Common mistakes:
append result.==.