Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Array index out of range - compile time

package main

import (
	"fmt"
)

func main() {
	var res = [3]int{7, 5, 9}

	fmt.Println(res)
	fmt.Println(res[4])
	fmt.Println(len(res))

	fmt.Printf("%T\n", res)
}
# command-line-arguments
./array_out_of_range.go:11:17: invalid array index 4 (out of bounds for 3-element array)