← All notes

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

Claims

Sources

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

Permanent ID: iil:note:vhsx4rga

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.},
}

Markdown

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.