当前位置:网站首页>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 :
边栏推荐
- PotPlayer设置最小化的快捷键
- Motivation du Protocole de chiffrement avancé AES
- FOC矢量控制及BLDC控制中的端电压、相电压、线电压等概念别还傻傻分不清楚
- Troubleshooting the cause of the crash when STM32 serial port dam receives 253 bytes
- Redis 过期策略+conf 记录
- golang中new与make的区别
- Brief introduction of emotional dialogue recognition and generation
- BBR 遭遇 CUBIC
- 【Proteus仿真】51单片机+LCD12864推箱子游戏
- Successfully changed Splunk default URL root path
猜你喜欢

Cryptography -- the mode of block cipher

程序员版本的八荣八耻~

Explain promise usage in detail

“一个优秀程序员可抵五个普通程序员!”

Redis expiration policy +conf record

Construction of Hisilicon 3559 universal platform: draw a frame on the captured YUV image

Talk about memory model and memory order

Niuke network: maximum submatrix

Set right click to select vs code to open the file

Win11如何开启目视控制?Win11开启目视控制的方法
随机推荐
Alibaba cloud award winning experience: how to use polardb-x
20220527_ Database process_ Statement retention
Tronapi wave field interface - source code without encryption - can be opened twice - interface document attached - packaging based on thinkphp5 - detailed guidance of the author - July 1, 2022 08:43:
Application of containerization technology in embedded field
Why does RTOS system use MPU?
阿里云有奖体验:如何使用 PolarDB-X
密码技术---密钥和SSL/TLS
Jerry's prototype has no touch, and the reinstallation becomes normal after dismantling [chapter]
Getting started with golang: for Range an alternative method of modifying the values of elements in slices
Doorplate making C language
Warning: implicitly declaring library function 'printf' with type 'int (const char *,...)‘
Learning Websites commonly used by circuit designers
海思 VI接入视频流程
Jericho's thimble reaction when directly touching the prototype is abnormal [chapter]
SharedPreferences 保存List<Bean> 到本地并解决com.google.gson.internal.LinkedTreeMap cannot be cast to异常
Lambda表达式:一篇文章带你通透
MarkDown基本语法
(毒刺)利用Pystinger Socks4上线不出网主机
STM32之ADC
Quantitative analysis of PSNR, SSIM and RMSE

