0
0
Goprogramming~20 mins

Go toolchain overview - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
๐ŸŽ–๏ธ
Go Toolchain Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
โ“ Predict Output
intermediate
2:00remaining
What is the output of this Go program using 'go run'?

Consider this Go program saved as main.go. What will be printed when you run go run main.go?

Go
package main
import "fmt"
func main() {
    fmt.Println("Hello, Go toolchain!")
}
AHello, Go toolchain!
Bmain.go:1:1: expected 'package', found 'import'
CError: cannot find package fmt
DNo output
Attempts:
2 left
๐Ÿ’ก Hint

Think about what go run does with a simple program that prints text.

๐Ÿง  Conceptual
intermediate
1:30remaining
Which Go tool command compiles packages and dependencies?

Which go tool command compiles the packages and their dependencies but does not run the program?

Ago test
Bgo install
Cgo build
Dgo run
Attempts:
2 left
๐Ÿ’ก Hint

Think about the command that creates an executable without running it.

โ“ Predict Output
advanced
2:00remaining
What error does this Go code produce when run with 'go run'?

What error message will this Go program produce when executed with go run?

Go
package main
func main() {
    var x int = "string"
}
Aundefined: x
Bno error, program runs successfully
Cmissing return statement
Dcannot use "string" (type string) as type int in assignment
Attempts:
2 left
๐Ÿ’ก Hint

Look at the variable type and the assigned value types.

๐Ÿง  Conceptual
advanced
1:30remaining
What does 'go install' do differently than 'go build'?

Choose the correct statement about the difference between go install and go build.

A<code>go install</code> runs tests, <code>go build</code> does not.
B<code>go install</code> compiles and places the executable in the Go bin directory, <code>go build</code> only compiles locally.
C<code>go install</code> deletes source files after compiling, <code>go build</code> keeps them.
D<code>go install</code> only downloads dependencies, <code>go build</code> compiles code.
Attempts:
2 left
๐Ÿ’ก Hint

Think about where the executable ends up after each command.

โ“ Predict Output
expert
2:00remaining
What is the output of this Go program using 'go run' with modules?

This Go program uses a module and imports fmt. What will be the output when running go run main.go inside a module-enabled directory?

Go
package main
import "fmt"
func main() {
    fmt.Println("Module enabled run")
}
AModule enabled run
Bcannot find module for path fmt
Cgo: no Go files in .
Dpanic: runtime error
Attempts:
2 left
๐Ÿ’ก Hint

Modules do not affect standard library imports like fmt.