Skip to content
Learn Netverks

Lesson

Step 16/36 44% through track

arrays-slices

Arrays and slices

Last reviewed May 28, 2026 Content v20260528
Track mode
server_compiled
Means
Compiled runner
Reading
~1 min
Level
intermediate

This lesson

This lesson teaches Arrays and slices: the syntax, patterns, and safety habits you need before advancing in Go.

Slices and maps are reference types—capacity, nil safety, and iteration pitfalls appear in every code review.

You will apply Arrays and slices in contexts like: Kubernetes ecosystem tools, cloud APIs, and CLI utilities.

Write Go in main.go with package main and func main(), click Run on server—the dev runner runs go run main.go; use fmt.Println for output (requires Go toolchain; LEARNING_RUNNER_ENABLED=true).

When you can explain the previous lesson's ideas without copying starter code.

Arrays have fixed length: [3]int. Slices are dynamic views over arrays: []int. Slices are used far more often—similar to Python lists but backed by contiguous arrays.

Slice internals

A slice is a header (pointer, length, capacity). append may reallocate backing arrays—copy if sharing underlying arrays matters. Slices are reference types; assigning aliases the same backing array.

Common operations

s := []int{1, 2, 3}
s = append(s, 4)
sub := s[1:3]  // half-open range

Important interview questions and answers

  1. Q: Array vs slice?
    A: Arrays fixed size, value type; slices dynamic length, reference to backing array.
  2. Q: append side effects?
    A: May reallocate—other slices sharing old array won't see new elements if capacity exceeded.

Self-check

  1. What does s[1:3] include?
  2. How do you add an element to a slice?

Tip: Slices share backing arrays—copy with append([]T(nil), s...) or slices.Clone when mutation must not alias.

Interview prep

Array vs slice?

Arrays fixed size and value type; slices dynamic views with pointer/len/cap header.

append reallocation?

May allocate new backing array—other subslices may not see new elements if capacity exceeded.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Playground

Runs on the configured server runner (dev: npm run runner with LEARNING_RUNNER_ENABLED=true). Output appears below the editor.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • Slice vs array?
  • append growth?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump