Go slices and arrays
Answer: A Go array has a fixed length that is part of its type; [4]int and [5]int are different types. A slice is a flexible view onto an underlying array with a length and capacity. Most Go code uses slices, growing them with append.
Arrays
var a [4]int // zero value: four zeros, ready to use
Arrays are values: assigning or passing one copies all elements.
Slices
s := make([]int, 3, 10) // length 3, capacity 10
s = append(s, 4)
t := s[1:3] // shares the same backing array
len(s): number of elements.
Claims
- id: C1 claim: An array's length is part of its type. source: S1 evidence: "An array’s size is fixed; its length is part of its type ([4]int and [5]int"
- id: C2 claim: Unlike an array type, a slice type has no specified length. source: S1 evidence: "Unlike an array type, a slice type has no specified length."
- id: C3 claim: Capacity defaults to the specified length when omitted. source: S1 evidence: "When the capacity argument is omitted, it defaults to the specified length."
- id: C4 claim: Length and capacity are inspected with len and cap. source: S1 evidence: "The length and capacity of a slice can be inspected using the built-in len and"
- id: C5 claim: Slices wrap arrays to give a more convenient interface. source: S2 evidence: "Slices wrap arrays to give a more general, powerful, and convenient"
Sources
- [S1] Go Slices: usage and internals - The Go Programming Language. The Go Authors (go.dev). https://go.dev/blog/slices-intro . License: CC BY 4.0 (go.dev text). Accessed 2026-11-04.
- [S2] Effective Go - The Go Programming Language. The Go Authors (go.dev). https://go.dev/doc/effective_go . License: CC BY 4.0 (go.dev text). Accessed 2026-11-04.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted).
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: The Go Authors (go.dev), Go Slices: usage and internals - The Go Programming Language, CC BY 4.0 (go.dev text); The Go Authors (go.dev), Effective Go - The Go Programming Language, CC BY 4.0 (go.dev text).
Cite this
iinventedlight. 2026. "Go slices and arrays." iinventedlight Library, iil:note:vhsx4rga, version of 2026-11-04. https://iinventedlight.com/library/notes/go-slices/. License: CC-BY-4.0.
@misc{iil_note_vhsx4rga,
author = {{iinventedlight}},
title = {{Go slices and arrays}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-04},
url = {https://iinventedlight.com/library/notes/go-slices/},
note = {Permanent ID iil:note:vhsx4rga. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com.
For language models and agents: start at /llms.txt. This page in Markdown: /library/notes/go-slices.md.