Skip to content

Instantly share code, notes, and snippets.

@dolmen
Created February 16, 2026 14:09
Show Gist options
  • Select an option

  • Save dolmen/8525e165d483b51fc3684642a8893257 to your computer and use it in GitHub Desktop.

Select an option

Save dolmen/8525e165d483b51fc3684642a8893257 to your computer and use it in GitHub Desktop.
Go slice can be explored beyond its len, up to its cap
// Demonstrates that the content of a slice beyond its current len can be retrieved up to its cap.
package main
import "testing"
func Test(t *testing.T) {
a := []byte("abcdef")
b := a[:3]
c := b[len(b):cap(b)]
t.Logf("a=%s, b=%s, c=%s\n", a, b, c)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment