Gaaker Go

Golang Declare array

The type [n]T is an array of n values of type T.

The expression

var a [5]int

Declare variable a as an array of five integers.

The length of the array is also part of the array type, so [5]int and [10]int are different types.

The following is a complete code example.

package main

import "fmt"

var a [3]int

func main() {
    var b [2]int


Below is the program output:

[0 0 0]
[0 0]
< Declare array Declare array >