Description
An array is a numbered sequence of elements of a specific length. The length is part of the array's type, so arrays cannot be resized. This makes them less common than Slices.
Pros & Cons
✅ Pros
- Value Semantics: Arrays are passed by value (copied).
- Predictable memory layout.
❌ Cons
- Fixed Size: Inflexible compared to slices.
When to Use
When you need a fixed-size buffer or lookup table.
Example
Declaring and initializing arrays.
var a [2]string
a[0] = "Hello"
a[1] = "World"
primes := [6]int{2, 3, 5, 7, 11, 13}
fmt.Println(primes)
Best Practices
Use arrays mostly as building blocks for slices. In 99% of app code, use Slices.
