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.go147 chars13 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.
gistlibby LogSnag