go by example part 2

This commit is contained in:
2022-01-01 19:47:24 +01:00
parent afe165089d
commit c1b7c64da2
10 changed files with 335 additions and 0 deletions

View File

@@ -0,0 +1,24 @@
package main
import "fmt"
// function that takes two ints and returns their sum as an int
// Go requires explicit returns
func plus(a int, b int) int {
return a + b
}
// multiple consecutive parameters of the same type,
// may omit the type name for the like-typed parameters up to the final parameter that declares the type
func plusPlus(a, b, c int) int {
return a + b + c
}
func main() {
// Call a function
res := plus(1, 2)
fmt.Println("1+2 =", res)
res = plusPlus(1, 2, 3)
fmt.Println("1+2+3 =", res)
}