首页 > 其他分享 >0084-Go-函数

0084-Go-函数

时间:2022-10-30 08:35:48浏览次数:101  
标签:函数 int res fmt Go func 0084 main

环境

  • 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 语言的函数。

附录

标签:函数,int,res,fmt,Go,func,0084,main
From: https://www.cnblogs.com/jiangbo4444/p/16840452.html

相关文章

  • 0085-Go-多返回值函数
    环境Time2022-08-23Go1.19前言说明参考:https://gobyexample.com/multiple-return-values目标使用Go语言的函数,返回两个值。直接返回packagemainimport"......
  • 0086-Go-可变参数函数
    环境Time2022-08-23Go1.19前言说明参考:https://gobyexample.com/variadic-functions目标使用Go语言的可变参数函数。可变参数函数packagemainimport"fm......
  • 0087-Go-闭包
    环境Time2022-08-23Go1.19前言说明参考:https://gobyexample.com/closures目标使用Go语言的闭包。示例packagemainimport"fmt"funcintSeq()func()i......
  • 0088-Go-递归
    环境Time2022-08-23Go1.19前言说明参考:https://gobyexample.com/closures目标使用Go语言的递归。递归函数packagemainimport"fmt"funcfact(nint)i......
  • 0089-Go-指针
    环境Time2022-08-23Go1.19前言说明参考:https://gobyexample.com/pointers目标使用Go语言的指针。示例packagemainimport"fmt"funczeroval(ivalint)......
  • 0090-Go-字符串
    环境Time2022-08-23Go1.19前言说明参考:https://gobyexample.com/strings-and-runes目标使用Go语言的字符串。字节遍历packagemainimport"fmt"funcma......
  • 0091-Go-结构体
    环境Time2022-08-24Go1.19前言说明参考:https://gobyexample.com/structs目标使用Go语言的结构体。直接使用结构体packagemainimport"fmt"typeperson......
  • 0092-Go-方法
    环境Time2022-08-24Go1.19前言说明参考:https://gobyexample.com/methods目标使用Go语言的方法。值方法packagemainimport"fmt"typerectstruct{......
  • 0093-Go-接口
    环境Time2022-08-24Go1.19前言说明参考:https://gobyexample.com/interfaces目标使用Go语言的接口。定义接口typegeometryinterface{area()float64......
  • 0094-Go-结构体嵌入
    环境Time2022-08-24Go1.19前言说明参考:https://gobyexample.com/struct-embedding目标使用Go语言的结构体嵌入。定义结构体typebasestruct{numint......