Arrays & Slices in Go

From the Go cheat sheet ยท Data Types & Structures ยท verified Jul 2026

Arrays & Slices

Working with arrays and slices

go
// Arrays (fixed size)
var arr [5]int
arr[0] = 10

// Slices (dynamic)
slice := []int{1, 2, 3}
slice = append(slice, 4)

// Make slice
s := make([]int, 5, 10) // len=5, cap=10
๐Ÿ“Š Arrays have fixed size, slices are dynamic
๐Ÿ”„ append() to add elements to slices
๐Ÿ“ฆ make() to create slices with capacity
โšก Slices are references to underlying arrays

More Go tasks

Back to the full Go cheat sheet