-
Define a function that gets two integers, adds them and returns the result
- Make sure to also write code that executes the function
-
What is the problem with the following code? How to fix it?
package main
import "fmt"
func add(x, y int) {
return x + y
}
func main() {
fmt.Println("Result:", add(2, 3))
}
package main
import "fmt"
func add(x, y int) int {
return x + y
}
func main() {
fmt.Println(add(2017, 2022))
}
- It returns an integer but at the same time the function doesn't specify any return value so Go expects the function to return nothing.