forked from jincheng9/go-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
/
constant.go
77 lines (63 loc) · 1.27 KB
/
constant.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package main
import "fmt"
/*
常量定义的时候必须赋值,定义后值不能被修改,否则编译报错
*/
const a int = 10
const b, c int = 20, 30
const d = "str"
const d1, d2 = "str1", "str2"
/*
常量可以定义枚举
*/
const (
unknown = 0
male = 1
female = 2
super
)
const (
flower = 1
wind = "ab"
sun // the value of sun is the same as wind, both are "ab"
)
const (
f1 = iota // f1 = 0
f2 // f2 = 1
f3 // f3 = 2
)
const (
v1 = iota // the value of v1 is 0
v2 = 1 << iota // current iota is 1, the value of v2 is 1<<1 = 2
v3 // current iota is 2, v3 = (1<<iota) = 1<<2 = 4
)
const h = iota // h = 0
const (
class1 = 0
class2 // class2 = 0
class3 = iota // class3 = 2
class4 // class4 = 3
class5 = "abc"
class6 // class6 = "abc"
class7 = iota // class7 is 6
)
func main() {
fmt.Println(a, b, c)
println(d)
println("d1=", d1, "d2=", d2)
println(unknown, male, female, super)
println(flower, wind, sun)
println("f1=", f1, "f2=", f2, "f3=", f3)
println(v1, v2, v3)
println("h=", h)
println("class value:", class1, class2, class3, class4, class5, class6, class7)
const g1 = iota // g=0
const g2 = iota
println("g1=", g1, "g2=", g2)
const (
h1 = 0
h2 = iota // h2 is 1
h3 // h3 is 2
)
println("h1=", h1, "h2=", h2, "h3=", h3)
}