首页 > 其他 > 详细

go_常量与枚举

时间:2018-03-10 15:15:13      阅读:237      评论:0      收藏:0      [点我收藏+]
package main

import (
	"fmt"
	"math"
)



//常量的数值可以作为各种类型使用
func consts(){
	const filename  = "abc.txt"
	//const a,b int= 3,4 常量可规定类型也可不规定
	const a,b = 3,4
	var c int
	c = int(math.Sqrt(float64(a * a + b * b)))
	fmt.Println(filename,c)
}

//枚举类型
func enums(){
	const (
		cpp = iota //const修饰的变量必须赋初值,iota表示自增
		_
		pyhon
		golang
	    javascrtpt
	)

	const (
		b = 1<<(10*iota)
		kb
		mb
		gb
		tb
	)
	fmt.Println(cpp,javascrtpt,pyhon,golang,)
	fmt.Println(b,kb,mb,gb,tb)
}

func main() {
	
	consts()
	enums()
}

  

常量的数值可以作为各种类型使用
const修饰的变量必须赋初值,iota表示自增

go_常量与枚举

原文:https://www.cnblogs.com/luffe/p/8538758.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!