Gaaker Go

Golang Arrays of arrays

Arrays are usually one-dimensional, but can be combined into multi-dimensional arrays, for example: [3][5]int, [2][2][2]float64.

The following is a complete code example.

package main

import "fmt"

const (
    WIDTH = 5
    HEIGHT = 6
)

func main() {

    var point [WIDTH][HEIGHT]int
    for i := 0; i <WIDTH; i++ {
        for j := 0; j <HEIGHT; j++ {
            point[i][j] = i + j
        }
    }
    fmt.Println(point)
}

Below is the program output:

[[0 1 2 3 4 5] [1 2 3 4 5 6] [2 3 4 5 6 7] [3 4 5 6 7 8] [4 5 6 7 8 9]]
< Arrays of arrays Arrays of arrays >