package main
import "fmt"
//单个返回值
func foo1(a int, b string) int {
fmt.Println("a=",a)
fmt.Println("b=",b)
c := 100
return c
}
//多个返回值,都是匿名
func foo2(a int, b string) (int,int){
fmt.Println("a=",a)
fmt.Println("b=",b)
return 100,200
}
//多个返回值,有形参名
func foo3(a int, b string) (r1 int,r2 int){
fmt.Println("a=",a)
fmt.Println("b=",b)
fmt.Println("赋值前:r1=",r1,",r2=",r2)
//给有名称的返回值变量赋值
r1 = 300
r2 = 400
return
}
//多个返回值,同种类型缩写
func foo4(a int, b string) (r1,r2 int){
fmt.Println("a=",a)
fmt.Println("b=",b)
fmt.Println("赋值前:r1=",r1,",r2=",r2)
//给有名称的返回值变量赋值
r1 = 300
r2 = 400
return
}
func main() {
fmt.Println("foo1 ---------------------------")
c := foo1(1,"bb")
fmt.Println("c=",c)
fmt.Println("foo2 ---------------------------")
d,e := foo2(1,"bb")
fmt.Println("d=",d)
fmt.Println("e=",e)
fmt.Println("foo3 ---------------------------")
r1,r2 := foo3(1,"bb")
fmt.Println("r1=",r1)
fmt.Println("r2=",r2)
}