当前位置:网站首页>Go basic constant definition and use
Go basic constant definition and use
2022-07-02 23:15:00 【Yi Yue Wang Chao】
Definition and use of basic constants :
Constants define code instances
package main func main() { // Constant definition : Can be called , It cannot be modified const PI = 3.1415926 r := 2.0 println(2*PI*r) // Set law defines constants const ( MALE = 1 FEMALE = 2 ) println(MALE, FEMALE) // Constant group definition considerations , If the type and initial value are not specified , Keep consistent with its previous line const ( x int = 16 y s string = "goho" z ) println(x, y, s, z) // Constant considerations : // 1. The data type of a constant can be Boolean 、 Numbers and strings // 2. Constants that have not been used will not report errors when compiling // 3. Constant group definition considerations , If the type and initial value are not specified , Keep consistent with its previous line }Running results :
iota Constant counter :
itoa yes go Language Constant automatic generator in , It doesn't follow c Language like enumerations can be generated implicitly , You must explicitly specify , The specific syntax is as follows :
- Constant combination assignment ,
iotaThe default from the 0 Start , Add one more each time : - Every time
iotaMeet a new oneconst, It will reset to 0: - Assign values to the same line ( List assignment ),
itoaThe value of does not change :
go Definition
package main func main() { // const Of iota Constant counter , // Constant definitions without expressions reuse the previous line of expressions const( a = iota // The default from the 0 Start b c ) println("iota Constant :", a, b, c) // each const Of iota Constant modules do not interfere with each other const ( x = iota y z ) println(" each iota Constant modules do not interfere with each other :", x, y, z) // How to learn from other non 0 How about the number // Constant definitions without expressions reuse the previous line of expressions // Pay attention to the meaning of adding one line by line const ( aa, bb = iota, iota cc = 10 dd, ee = iota, iota ) println(aa, bb, cc, dd, ee) }Running results :
边栏推荐
- 密码技术---密钥和SSL/TLS
- C#中Linq用法汇集
- 购买完域名之后能干什么事儿?
- [redis notes] compressed list (ziplist)
- How does Jerry test the wrong touch rate of keys [chapter]
- Troubleshooting the cause of the crash when STM32 serial port dam receives 253 bytes
- 深度剖析数据在内存中的存储----C语言篇
- 密码技术---分组密码的模式
- Eight bit responder [51 single chip microcomputer]
- Prometheus deployment
猜你喜欢
随机推荐
20220527_数据库过程_语句留档
Boost库链接错误解决方案
ping域名报错unknown host,nslookup/systemd-resolve可以正常解析,ping公网地址通怎么解决?
为什么RTOS系统要使用MPU?
[chestnut sugar GIS] how does global mapper batch produce ground contour lines through DSM
阿里云有奖体验:如何使用 PolarDB-X
“一个优秀程序员可抵五个普通程序员!”
Win11系统explorer频繁卡死无响应的三种解决方法
Getting started with golang: for Range an alternative method of modifying the values of elements in slices
归并排序详解及应用
Jerry's prototype has no touch, and the reinstallation becomes normal after dismantling [chapter]
設置單擊右鍵可以選擇用VS Code打開文件
1px pixel compatibility of mobile terminal, 1px border
Explain promise usage in detail
【Proteus仿真】51单片机+LCD12864推箱子游戏
golang中new与make的区别
用matlab调用vs2015来编译vs工程
Sword finger offer II 099 Sum of minimum paths - double hundred code
情感对话识别与生成简述
4 special cases! Schools in area a adopt the re examination score line in area B!










![[Yangcheng cup 2020] easyphp](/img/12/da28f738e50e625b0a66a94af3703d.png)
