create an array with a length of type string in go

To create an array with a length of type string in Go, you would first need to define the length of the array and then initialize each element of the array with a string value.

Here's an example of how to create an array with a length of 3 and type string:

main.go
package main

import "fmt"

func main() {
   var arr [3]string
   arr[0] = "hello"
   arr[1] = "world"
   arr[2] = "golang"

   fmt.Println(arr)
}
147 chars
13 lines

This will output: [hello world golang].

In this example, we first created an array called arr with a length of 3 using the syntax var arr [3]string. We then assigned a string value to each element of the array using the index notation (arr[0], arr[1], arr[2]). Finally, we printed the entire array using fmt.Println(arr) statement.

related categories

gistlibby LogSnag