当前位置:网站首页>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 :
边栏推荐
- golang中new与make的区别
- BBR encounters cubic
- 阿里云有奖体验:如何使用 PolarDB-X
- Value sequence < detailed explanation of daily question >
- Tiktok actual combat ~ number of likes pop-up box
- Chow-Liu Tree
- Jerry's prototype will trigger shutdown after multiple touches [chapter]
- FOC矢量控制及BLDC控制中的端电压、相电压、线电压等概念别还傻傻分不清楚
- Getting started with golang: for Range an alternative method of modifying the values of elements in slices
- Why does RTOS system use MPU?
猜你喜欢

归并排序详解及应用

Set right click to select vs code to open the file
![[npuctf2020]ezlogin XPath injection](/img/6e/dac4dfa0970829775084bada740542.png)
[npuctf2020]ezlogin XPath injection

最小生成树 Minimum Spanning Tree

Go language sqlx library operation SQLite3 database addition, deletion, modification and query

密码技术---分组密码的模式

Minimum spanning tree

Application of containerization technology in embedded field

Typical case of data annotation: how does jinglianwen technology help enterprises build data solutions

Loss function~
随机推荐
[chestnut sugar GIS] how does global mapper batch produce ground contour lines through DSM
Cryptographic technology -- key and ssl/tls
Redis expiration policy +conf record
解决:exceptiole ‘xxxxx.QRTZ_LOCKS‘ doesn‘t exist以及mysql的my.cnf文件追加lower_case_table_names后启动报错
Win11麦克风测试在哪里?Win11测试麦克风的方法
购买完域名之后能干什么事儿?
[hardware] origin of standard resistance value
[chestnut sugar GIS] ArcScene - how to make elevation map with height
Set right click to select vs code to open the file
2016. maximum difference between incremental elements
Quantitative analysis of PSNR, SSIM and RMSE
Introduction to the latest plan of horizon in April 2022
Pandora IOT development board learning (HAL Library) - Experiment 4 serial port communication experiment (learning notes)
Arduino - 字符判断函数
AES高級加密協議的動機闡述
Loss function~
Lambda表达式:一篇文章带你通透
QT qpprogressbar details
严守工期,确保质量,这家AI数据标注公司做到了!
Win11如何开启目视控制?Win11开启目视控制的方法

