0PricingLogin
Go Academy · Lesson

Arrays: Fixed-Length Collections

Array literals, indexing, and length

What Is an Array?

An array in Go is a fixed-length sequence of elements of the same type. The length is part of the type: [3]int and [4]int are different types.

  • Arrays are value types — assigning copies the entire array
  • Length is always known at compile time
  • Rarely used directly; slices are preferred for most tasks

Array Literals

Declare and initialize arrays with a literal:

package main

func main() {
    primes := [5]int{2, 3, 5, 7, 11}
    names  := [3]string{"Alice", "Bob", "Carol"}
    flags  := [4]bool{true, false, true, false}
    _ = primes; _ = names; _ = flags
}

All lessons in this course

  1. Arrays: Fixed-Length Collections
  2. Slices: Dynamic Lists
  3. Maps: Key-Value Stores
  4. Iterating Collections with range
← Back to Go Academy