package main import "fmt" func main() { arr := [3]int{1, 2, 3} slice := arr[:] slice = append(slice, 4) fmt.Println(len(arr), len(slice)) }
The array has fixed length 3. The slice initially references the array but append creates a new underlying array with length 4. So arr length is 3, slice length is 4.
Arrays store elements contiguously, allowing O(1) access by index. Linked lists require traversal, so arrays are better for fast random access.
package main import "fmt" func modify(arr *[3]int) { (*arr)[0] = 10 } func main() { a := [3]int{1, 2, 3} modify(&a) fmt.Println(a) }
The function receives a pointer to the array and modifies the first element. This change reflects in the original array, so output is [10 2 3].
package main
func main() {
var a [3]int = [3]int{1, 2, 3}
var b [4]int = a
}Arrays with different sizes are different types in Go. Assigning [3]int to [4]int causes a compile-time type mismatch error.
Arrays have fixed size, store elements contiguously, and provide O(1) access by index with minimal overhead compared to other structures.
