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
<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
Copy an array by value and reference into another array
Initializing an Array with ellipses in Go
Golang check if array element exists
How to initialize an Array with an Array Literal in Go?
What is an Array in Go?
How to assign and access array element values in Go?
Tricks to filter array elements in Go
Initialize values for specific array elements in Go
How to iterate over an Array using for loop?
Most Helpful This Week
Example: How to use ReadAtLeast from IO Package in Golang?Converting Int data type to Float in GoHigher Order Functions in GolangHow to import structs from another package in Go?Generate a Keygen of 256 bitsFind length of Channel, Pointer, Slice, String and MapDynamic JSON parser without Struct in GolangReplace numbers by zero from stringRegular expression to extract DNS host-name or IP Address from stringExample: Arrays of Arrays, Arrays of Slices, Slices of Arrays and Slices of Slices