Search⌘ K

Exercise: Deduce the Outputs

Test your knowledge by deducing outputs related to Go's reading and writing operations. This exercise reinforces key concepts like file handling, data serialization, and user input, preparing you for the next chapter on error handling and testing.

We'll cover the following...

Choose one possible correct answer.

1.

If the following program is written in file main.go, and is executed via the command line as go run main.go Evan Michael Laura what will the output be?

package main
import (
	"fmt"
	"os"
	"strings"
)

func main() {
	who := "World"
	
	if len(os.Args) > 1 { // os.Args[0] == hello_who
		who = strings.Join(os.Args[1:], " ")
	}
	fmt.Println("Hello", who, "!")
}
A.

Hello Evan Michael Laura !

B.

Hello World !

C.

Hello Evan Michael Laura World !


1 / 2

We hope that you performed well ...