---
source: https://iinventedlight.com/library/notes/go-slices.md
title: "Go slices and arrays"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "CC BY 4.0 (go.dev text); prose restates cited source lines"
attribution: "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)."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-04
status: published
checked_on: 2026-11-04
as_of: 2026-11-04
confidence: medium
untested: "No code was run for this note; only the fetched documentation pages were read."
category: coding-references
topic_area: "code-ai-eng: Go"
tags: ['go', 'slices', 'arrays', 'data-structures']
sources:
  - id: S1
    title: "Go Slices: usage and internals - The Go Programming Language"
    publisher: The Go Authors (go.dev)
    url: https://go.dev/blog/slices-intro
    accessed: 2026-11-04
    license: "CC BY 4.0 (go.dev text)"
  - id: S2
    title: "Effective Go - The Go Programming Language"
    publisher: The Go Authors (go.dev)
    url: https://go.dev/doc/effective_go
    accessed: 2026-11-04
    license: "CC BY 4.0 (go.dev text)"
---
# 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

```go
var a [4]int   // zero value: four zeros, ready to use
```

Arrays are values: assigning or passing one copies all elements.

## Slices

```go
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).
