Boldly Go
Blog YouTube Hire Me Contact Daily Email
Boldly Go
Blog YouTube Hire Me Contact Daily Email
Go Language Spec

2 min read


Range of slice expressions

Simple slice expressions … For arrays or strings, the indices are in range if 0 <= low <= high <= len(a), otherwise they are out of range. This is probably intuitive. a := [5]int{1, 2, 3, 4, 5} s := "Abracadabra" a[-1] // Out of range s[5:1] // Out of range a[12] // Out of range s[999] // Out of range For slices, the upper index bound is the slice capacity cap(a) rather than the length.

Quiz Challenge

1 min read


Quiz

Today’s quiz day. Tomorrow I’ll provide the answer as we continue with the section of the spec that explains today’s code. Consider the following program. What is its output? package main import "fmt" func main() { a := []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10} s := a[2:5] s2 := s[5:7] fmt.Println(s2) } [6 7] [8 9] A runtime panic A compilation error

My Content

  • Boldly Go: Daily
  • YouTube

My Services

  • Dev Subscription
  • Private Mentoring

About me

  • Contact Me
  • Privacy Policy

Subscribe to Boldly Go: Daily

Daily suggestions to improve your control of the Go language. I will respect your inbox, and honor my privacy policy.

Not convinced? Browse the archive.

© 2025 Jonathan Hall. All rights reserved.