How to use array in Go Programming Language?
Example
package main
import "fmt"
func main(){
var x[5] int // Array Declaration
x[0]=10 // Assign the values to specific Index
x[4]=20 // Assign Value to array index in any Order
x[1]=30
x[3]=40
x[2]=50
fmt.Println("Values of Array X: ",x)
// Array Declartion and Intialization to specific Index
y := [5]int{0:100,1:200,3:500}
fmt.Println("Values of Array Y: ",y)
// Array Declartion and Intialization
Country := [5]string{"US","UK","Australia","Russia","Brazil"}
fmt.Println("Values of Array Country: ",Country)
// Array Declartion without length and Intialization
Transport := [...]string{"Train","Bus","Plane","Car","Bike"}
fmt.Println("Values of Array Transport: ",Transport)
}
Most Helpful This Week
Dynamic XML parser without Struct in Go
How to trim leading and trailing white spaces of a string in Golang?
How pointer & and * and ** works in Golang?
Golang Read Write Create and Delete text file
How to read names of all files and folders in current directory?
Golang Read Write and Process data in CSV