funcparamFunc(a int, b *int, c []int){
a =100*b =100
c[1]=100
fmt.Println("paramFunc:")
fmt.Println(a)
fmt.Println(*b)
fmt.Println(c)}funcmain(){
a :=1
b :=1
c :=[]int{1,2,3}paramFunc(a,&b, c)
fmt.Println("main:")
fmt.Println(a)
fmt.Println(b)
fmt.Println(c)}
变长函数
funcmain(){
slice :=[]int{7,9,3,5,1}
x :=min(slice...)
fmt.Printf("The minimum is: %d", x)}funcmin(s ...int)int{iflen(s)==0{return0}
min := s[0]for_, v :=range s {if v < min {
min = v
}}return min
}
匿名函数
funcmain(){
f :=func()string{return"hello world"}
fmt.Println(f())}
闭包
funcadd()func(int)int{
n :=10
str :="string"returnfunc(x int)int{
n = n + x
str += strconv.Itoa(x)
fmt.Print(str," ")return n
}}funcmain(){
f :=add()
fmt.Println(f(1))
fmt.Println(f(2))
fmt.Println(f(3))
f =add()
fmt.Println(f(1))
fmt.Println(f(2))
fmt.Println(f(3))}