Bird
Raised Fist0
Goprogramming~20 mins

Go toolchain overview - Practice Problems & Coding Challenges

Choose your learning style10 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.

Practice

(1/5)
1. Which Go toolchain command is used to create an executable file from your Go source code?
easy
A. go build
B. go run
C. go fmt
D. go test

Solution

  1. Step 1: Understand the purpose of go build

    The go build command compiles your Go source code into an executable file.
  2. Step 2: Compare with other commands

    go run runs code without creating an executable, go fmt formats code, and go test runs tests.
  3. Final Answer:

    go build -> Option A
  4. Quick Check:

    Executable creation = go build [OK]
Hint: Build creates executables; run just executes code [OK]
Common Mistakes:
  • Confusing go run with go build
  • Thinking go fmt builds code
  • Using go test to build executables
2. Which of the following is the correct syntax to run a Go program file named main.go using the Go toolchain?
easy
A. go build main.go
B. go test main.go
C. go run main.go
D. go fmt main.go

Solution

  1. Step 1: Identify the command to run code directly

    go run compiles and runs the Go program immediately without creating an executable.
  2. Step 2: Check other commands

    go build compiles but does not run, go fmt formats code, and go test runs tests, so they are not for running directly.
  3. Final Answer:

    go run main.go -> Option C
  4. Quick Check:

    Run code immediately = go run [OK]
Hint: Use go run to execute files quickly [OK]
Common Mistakes:
  • Using go build to run code directly
  • Trying to run tests with go run
  • Confusing go fmt as a run command
3. What will be the output when you run the following commands in order?
go fmt main.go
 go build main.go
 ./main

Assuming main.go contains a valid Go program that prints "Hello, Go!".
medium
A. Syntax error
B. Hello, Go!
C. No output
D. Compilation error

Solution

  1. Step 1: Understand each command's effect

    go fmt main.go formats the code but does not affect output. go build main.go compiles the code into an executable named main. ./main runs the executable.
  2. Step 2: Predict the program output

    Since main.go prints "Hello, Go!", running ./main will output exactly that.
  3. Final Answer:

    Hello, Go! -> Option B
  4. Quick Check:

    Build then run prints program output [OK]
Hint: Build creates executable; run it to see output [OK]
Common Mistakes:
  • Expecting go fmt to produce output
  • Confusing build errors with formatting
  • Not running the executable after build
4. You run go test on your Go package, but it reports no tests found. What is the most likely reason?
medium
A. Your test functions are not named starting with Test
B. You forgot to run go build first
C. You need to run go fmt before testing
D. Your Go version is outdated

Solution

  1. Step 1: Understand Go test naming conventions

    Go requires test functions to start with Test (e.g., TestFunction) to detect and run them.
  2. Step 2: Check other options

    go build is not required before testing, go fmt only formats code, and outdated Go versions usually cause errors, not silent no tests.
  3. Final Answer:

    Test functions not named starting with Test -> Option A
  4. Quick Check:

    Test function names start with 'Test' [OK]
Hint: Test functions must start with 'Test' to run [OK]
Common Mistakes:
  • Assuming build is needed before test
  • Thinking formatting affects test detection
  • Blaming Go version without checking test names
5. You want to automate your Go project workflow to format code, run tests, and then build the executable only if tests pass. Which sequence of commands correctly achieves this?
hard
A. go build && go test && go fmt
B. go fmt && go build && go test
C. go test && go fmt && go build
D. go fmt ./... && go test ./... && go build

Solution

  1. Step 1: Understand command order for workflow

    First, go fmt ./... formats all code files recursively. Then, go test ./... runs all tests. Using && ensures the next command runs only if the previous succeeds.
  2. Step 2: Confirm build runs only after tests pass

    go build runs last, so it only executes if tests pass, ensuring a clean build.
  3. Final Answer:

    go fmt ./... && go test ./... && go build -> Option D
  4. Quick Check:

    Format, test, then build with && [OK]
Hint: Use && to chain commands; build last after tests pass [OK]
Common Mistakes:
  • Building before testing
  • Running tests after build
  • Not chaining commands to stop on failure
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard