Saturday 26 September 2020

golang 6 function 1

 package main

import "fmt"

func add(x, y int) (z1, z2 int) {
defer fmt.Println("after return")
z1 = x + y
z2 = x - y
fmt.Println("before return")
return
}

func main() {
ans1, ans2 := add(14, 7)
fmt.Println(ans1, ans2)
}

//cmd
PS C:\Users\bob\golang1> go run tutorial.go
before return
after return
21 7

reference:

No comments:

Post a Comment