Recall & Review
beginner
What is a function declaration in Go?
A function declaration in Go defines a reusable block of code with a name, optional parameters, and an optional return type. It tells the program what the function does when called.
Click to reveal answer
beginner
How do you declare a simple function named
greet that prints "Hello" in Go?You write:<br>
func greet() {
fmt.Println("Hello")
}<br>This declares a function named greet with no parameters and no return value.Click to reveal answer
intermediate
What is the syntax to declare a function with parameters in Go?
You list parameters inside parentheses after the function name, each with a name and type. For example:<br>
func add(a int, b int) int {
return a + b
}<br>This function takes two integers and returns an integer.Click to reveal answer
intermediate
Can a Go function return multiple values? How?
Yes, Go functions can return multiple values by listing return types in parentheses. Example:<br>
func swap(x, y string) (string, string) {
return y, x
}<br>This function returns two strings.Click to reveal answer
beginner
What keyword starts a function declaration in Go?
The keyword
func starts every function declaration in Go. It signals that a function is being defined.Click to reveal answer
Which keyword is used to declare a function in Go?
✗ Incorrect
In Go, the keyword
func is used to declare functions.How do you declare a function named
sum that takes two integers and returns an integer?✗ Incorrect
Option C correctly uses Go syntax with
func, parameter types, and return type.Can a Go function return more than one value?
✗ Incorrect
Go supports multiple return values by listing them in parentheses after the function parameters.
What is the correct way to declare a function with no parameters and no return value?
✗ Incorrect
In Go, empty parentheses indicate no parameters, and no return type means no return value.
Which of these is a valid function declaration in Go?
✗ Incorrect
Option B correctly declares parameter type and return type with proper syntax.
Explain how to declare a function in Go that takes parameters and returns a value.
Think about the order: func, name, parameters, return type, then body.
You got /5 concepts.
Describe how Go functions can return multiple values and why this might be useful.
Remember Go often returns error as a second value.
You got /3 concepts.