Declaring an Integer or String Array of Five Elements in Go

Declaring an Array
To declare an array, you use the following syntax

Syntax

var array_name [size_of_array]data_type
The following program declares an array called intArray and strArray of type int and string with five elements respectively:
<pre class="language-jsx"><code class="  language-jsx">package main

import (
	"fmt"
	"reflect"
)

func main() {
	var intArray [5]int
	var strArray [5]string

	fmt.Println(reflect.ValueOf(intArray).Kind())
	fmt.Println(reflect.ValueOf(strArray).Kind())
}</code></pre>
<pre class="language-jsx"><code class="  language-jsx">array
array</code></pre>

Most Helpful This Week