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
Convert specific UTC date time to PST, HST, MST and SGT
Get Year, Month, Day, Hour, Min and Second from current date and time.
How to read current directory using Readdir?
Golang download image from given URL
Various examples of printing and formatting in Golang
How to get the current date and time with timestamp in local and other timezones ?
Example: How to use ReadFull from IO Package in Golang?
How to collect information about garbage collection?
How to create a photo gallery in Go?
How to declare and access pointer variable?