1. 程式人生 > >Go基礎之iota

Go基礎之iota

main 修改 兩個 編譯器 fun clas 表達式 ack 其他

iota與true、false被定義為預定義常量

iota又比較特殊,其他的常量在編譯期間就確定了值,但是iota的值可以被編譯器修改

代碼示例:

package main

import "fmt"

func main()  {
	const (
		a = iota
		b	
		c
	)
	const (
		u     = iota*2
		v     = iota*4
		w int = iota*6
	)
	fmt.Println(a,b,c)
	fmt.Println(u,v,w)
}

說明:

1、如果兩個const的賦值語句的表達式是一樣的,那麽可以省略後一個賦值表達式

2、iota在每個const出現之時被重置為0

Go基礎之iota