Skip to content

Commit b1d4e02

Browse files
committed
update lesson8
1 parent 58d5b5b commit b1d4e02

File tree

2 files changed

+71
-1
lines changed

2 files changed

+71
-1
lines changed

workspace/lesson8/func.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package main
2+
3+
4+
func add(a, b int, c, d string) (int, string) {
5+
return a+b, c+d
6+
}
7+
8+
func main() {
9+
a, b := 1, 2
10+
c, d := "c", "d"
11+
res1, res2 := add(a, b, c, d)
12+
println("res1=", res1, "res2=", res2)
13+
}

workspace/lesson8/readme.md

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,71 @@
11
# 函数
22

33
* 函数定义
4+
5+
```go
6+
func name([parameter list]) [return_types] {
7+
do sth
8+
}
9+
```
10+
11+
12+
413
* 无参数
14+
15+
```go
16+
func name() int {
17+
do sth
18+
}
19+
```
20+
21+
22+
523
* 无返回值
24+
25+
```go
26+
func name(a int) {
27+
do sth
28+
}
29+
```
30+
31+
32+
633
* 返回1个值
34+
35+
```go
36+
func name(a int) int {
37+
do sth
38+
}
39+
```
40+
41+
42+
743
* 返回多个值
44+
45+
```go
46+
func name(a int) (int, string) {
47+
do sth
48+
}
49+
func name(a b int) (int, string) {
50+
do sth
51+
}
52+
func name(a int, b string)(int, string) {
53+
do sth
54+
}
55+
func name(a, b int, c, d string) (int, string) {
56+
do sth
57+
}
58+
```
59+
60+
61+
862
* 函数参数
63+
964
* 值传递
10-
* 引用传递
65+
* 引用传递:指针
66+
1167
* 函数高级用法
68+
1269
* 函数作为另一个函数的实参
1370
* 闭包
1471
* 方法

0 commit comments

Comments
 (0)