Recall & Review
beginner
What does it mean when a Go function has multiple return values?
It means the function can send back more than one result at the same time, like returning both a value and an error.
Click to reveal answer
beginner
How do you declare a function in Go that returns two values, an int and an error?
You write the return types in parentheses, like:
func example() (int, error).Click to reveal answer
beginner
Why are multiple return values useful in Go?
They let you return extra information, like an error, without needing special structures. This helps keep code simple and clear.Click to reveal answer
intermediate
Given this function signature:
func divide(a, b int) (int, error), what should the function return if b is zero?It should return zero and an error explaining division by zero is not allowed.
Click to reveal answer
beginner
How do you capture multiple return values from a function call in Go?
You assign them to multiple variables separated by commas, like:
result, err := divide(10, 2).Click to reveal answer
What is the correct way to declare a Go function that returns a string and an error?
✗ Incorrect
In Go, multiple return types are enclosed in parentheses and separated by commas.
How do you receive two return values from a Go function call?
✗ Incorrect
Use comma-separated variables with := to receive multiple return values.
Why might a Go function return an error as a second value?
✗ Incorrect
Returning an error helps the caller know if the function succeeded or failed.
What happens if you ignore the second return value (error) in Go?
✗ Incorrect
You can ignore the error but it is risky because you might miss important problems.
Which of these is a valid way to return multiple values in Go?
✗ Incorrect
Go returns multiple values separated by commas without extra brackets.
Explain how multiple return values work in Go and why they are useful.
Think about how functions can send back both results and errors.
You got /3 concepts.
Describe how you would write and call a Go function that returns a number and an error.
Remember to use parentheses for return types and comma to receive values.
You got /3 concepts.