An array of language study notes go

package main

import (
    "fmt"
)

func main() {
    // Declare arrays
    var x[5] int
    //Assign value at specific index
    x[0] = 5
    x[4] = 25
    fmt.Printf("Value of x:",x)
    x[1] = 10
    x[2] =15
    x[3] = 20
    fmt.Printf("Value of x:",x)

    //Declare and initialize array with array literal
    y := [5] int{10,20,30,40}
    fmt.Printf("Value of y",y)

    //Array literal with ...
    z := [...] int {10,20,30,40,50}
    fmt.Printf("Value of z",z)
    fmt.Printf("Length of z:",len(z))

    //Initialize values at specific index with array literal
    langs :=[4]string{0:"Go",3:"Julia"}
    fmt.Printf("Value of langs",langs)
    // Assign values to remaining postion
    langs[1] = "Rust"
    langs[2] = "Scala"

    // Iterate over the elements of array
    fmt.Printf("Value of langs",langs)
    println("\nItearator over aarays\n")
    for i:=0;i<len(langs);i++{
        fmt.Printf("langs[%d]:%s \n",i,langs[i])
    }
    //Iterator over the elements of array using range
    for k,v:=range langs{
        println(k,v)
    }

}

Guess you like

Origin www.cnblogs.com/c-x-a/p/11163949.html