xxxxxxxxxx
package main
import "fmt"
// function definition
func addNumbers(n1 int, n2 int) int {
sum := n1 + n2
return sum
}
func main() {
// function call
result := addNumbers(21, 13)
fmt.Println("Sum:",result)
}
xxxxxxxxxx
package main
import "fmt"
func greet() func() {
return func() {
fmt.Println("Hi John")
}
}
func main() {
g1 := greet()
g1()
}
xxxxxxxxxx
// Function with int as return type
func add(x int, y int) int {
total := 0
total = x + y
return total
}
func main() {
// Accepting return value in varaible
sum := add(20, 30)
fmt.Println(sum)
}