一句话总结:const语句块的行索引,从0开始累加。注意与C++中枚举类的区分。
1、iota从0开始,b、c依次等于累加的索引
2、a1=1<<3=8,b1、c1也类似=1<<iota
3、d、e、f、g会等于上面的值,不累加,与枚举类不同。
package main
import "fmt"
func main() {
const (
a = iota
b
c
a1 = 1 << iota
b1
c1
d = " hei "
e
f = 2
g
h = iota
j
)
fmt.Println("hello world")
fmt.Print(a, b, c, a1, b1, c1, d, e, f, g, h, j)
运行结果:
hello world
0 1 2 8 16 32 hei hei 2 2 10 11