常量const包含不变的数据。此数据只能是布尔型, 数字(整数, 浮点数或复数)或字符串类型。
句法:
const identifier [type] = value
例:
const PI = 3.14159
类型说明符[type]是可选的, 编译器可以从值隐式派生类型。
显式键入示例:
const b string = "abc"
隐式键入示例:
const b = "abc"
转到常量示例
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
微信公众号
手机浏览(小程序)
Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages:
error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in
/mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line
57
Warning: get_headers(): Failed to enable crypto in
/mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line
57
Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_50063.jpg): failed to open stream: operation failed in
/mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line
57