GO教程
GO控制语句
GO高级

Go 常量

Go 常量

常量const 包含未更改的数据。此数据只能是布尔值、数字(整数、浮点数或复数)或字符串类型。
语法:
const identifier [type] = value
示例:
const PI = 3.14159
类型说明符 [type] 是可选的,编译器可以从值中隐式派生类型。
显式键入示例:
const b string = "abc"
隐式输入示例:
const b = "abc"

Go 常量示例

package main
import "fmt"
func main() {
   const HEIGHT int = 100
   const WIDTH int = 200
   var area int
   area = HEIGHT * WIDTH
   fmt.Printf("value of area : %d", area)
}
输出:
value of area : 20000

昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4