package main
import (
"fmt"
)
func main() {
A()
fmt.Println("B():", B())
C(3, 5)
a, b := D()
_, c := D() // 底線代表不使用
d, _ := D() // 底線代表不使用
fmt.Println("D():", a, b, c, d)
fmt.Print("E():")
fmt.Println(E(5, 7))
fmt.Print("F():")
fmt.Println(F(5, 7))
fmt.Println("G():", G())
H(1, 2, 3, 4, 5)
i := func(x int) int {
return x * x
}
fmt.Println("I():", i(5))
j := map[int]func() int{
1: func() int { return 10 },
2: func() int { return 20 },
3: func() int { return 30 },
}
fmt.Println("J():", j[1])
}
func A() {
fmt.Println("A(): Hi..嗨 ~")
}
func B() string {
return "Hello 你好 !"
}
func C(x int, y int) {
fmt.Println("C():", x, y)
}
func D() (int, int) {
return 1, 2
}
func E(x int, y int) (int, int) {
return x + 5, y + 5
}
func F(x int, y int) (a int, b int) {
a = x + 5
b = x + 5
return a, b
}
func G() (x int) {
defer func() {
x++
}()
return 0
}
func H(a ...int) {
fmt.Print("H():")
for n := range a {
fmt.Print(n)
}
fmt.Println()
}
輸出結果:
A(): Hi..嗨 ~
B(): Hello 你好 !
C(): 3 5
D(): 1 2 2 1
E():10 12
F():10 10
G(): 1
H():01234
I(): 25
J(): 0x401cbe
留言列表