Command-line arguments

main.go

package main

import (
    "os"
    "fmt"
)

func main() {
    var s, sep string
    for i := 1; i < len(os.Args); i++ { //os.Args[0] contains the name of file. I could also use range
        s += sep + os.Args[i] // concatenation. Not efficient for multiple concatenations
        sep = " "
    }
    fmt.Println(s)
}
go run main.go 1 2 3

Output:

1 2 3

Efficient code

package main

import (
    "os"
    "fmt"
)

func main() {
    fmt.Println(strings.Join(os.Args[1:], " "))

}

Output:

1 2 3

results matching ""

    No results matching ""