0084-Go-函数

环境

  • Time 2022-08-23
  • Go 1.19

前言

说明

参考:https://gobyexample.com/functions

目标

使用 Go 语言的函数。

定义函数

func plus(a int, b int) int {
    return a + b
}

使用函数

package main

import "fmt"

func plus(a int, b int) int {
    return a + b
}

func main() {
    res := plus(1, 2)
    fmt.Println("1+2 =", res)
}

参数类型简写

package main

import "fmt"

func plusPlus(a, b, c int) int {
    return a + b + c
}

func main() {

    res := plusPlus(1, 2, 3)
    fmt.Println("1+2+3 =", res)
}

总结

使用 Go 语言的函数。

附录

posted @ 2022-10-30 08:18  jiangbo4444  阅读(25)  评论(0)    收藏  举报