Skip to content

learning6

Doifo edited this page Jun 9, 2023 · 1 revision

函数

函数的声明包括以下几部分

func 函数名(形式参数列表) (返回值列表) {
    函数体
}

多个形参

...int标识该函数可以接收多个int参数

func sum(args ...int) {
	xxx
}

返回值

函数可以有多个返回值,并且可以返回带有变量名的值,return不需要直接返回变量

func double(a int) (b int) {
    b = a * 2
    return
}
Clone this wiki locally