Array — fixed-length, value-type where length is part of the type. Slice — dynamic-length reference type backed by an array, the standard Go collection.
Arrays have their length baked into the type, so [3]int and [4]int are different types. They are value types — assigning or passing copies all elements. Arrays are comparable and can be map keys.
1arr := [3]int{10, 20, 30}2arr2 := arr // full copy3arr2[0] = 994fmt.Println(arr[0]) // 10 — unchanged
Slices are views into arrays with pointer, length, and capacity. They share backing memory — multiple slices can reference the same array. append may reallocate when capacity is exceeded.
1nums := []int{1, 2, 3, 4, 5}2first3 := nums[:3] // shares backing array3first3[0] = 1004fmt.Println(nums[0]) // 100 — shared mutation!5nums = append(nums, 6) // may reallocate
When to use:
Common mistakes:
append — append returns a new slice header.== — only valid against nil.