当前位置:网站首页>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 :
边栏推荐
- Talk about memory model and memory order
- Quantitative analysis of PSNR, SSIM and RMSE
- Lambda expression: an article takes you through
- BBR encounters cubic
- golang入门:for...range修改切片中元素的值的另类方法
- Win11如何开启目视控制?Win11开启目视控制的方法
- SharedPreferences 保存List<Bean> 到本地并解决com.google.gson.internal.LinkedTreeMap cannot be cast to异常
- Static file display problem
- Ping domain name error unknown host, NSLOOKUP / system d-resolve can be resolved normally, how to Ping the public network address?
- Go multithreaded data search
猜你喜欢

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

详解Promise使用
![[favorite poems] OK, song](/img/1a/e4a4dcca494e4c7bb0e3568f708288.png)
[favorite poems] OK, song

Start from the bottom structure to learn the customization and testing of FPGA --- Xilinx ROM IP
![[hardware] origin of standard resistance value](/img/d1/b9184c508d363eb0fa018ea6a57a10.png)
[hardware] origin of standard resistance value

Introduction to the latest plan of horizon in April 2022

Value sequence < detailed explanation of daily question >

QT qpprogressbar details

海思 VI接入视频流程

数据标注典型案例,景联文科技如何助力企业搭建数据方案
随机推荐
Cryptographic technology -- key and ssl/tls
Generics and reflection, this is enough
Typical case of data annotation: how does jinglianwen technology help enterprises build data solutions
xshell配置xforward转发火狐浏览器
Eight bit responder [51 single chip microcomputer]
[hardware] origin of standard resistance value
数据标注典型案例,景联文科技如何助力企业搭建数据方案
从底层结构开始学习FPGA----Xilinx ROM IP的定制与测试
Mask R-CNN
The use of 8255 interface chip and ADC0809
20220527_数据库过程_语句留档
Quantitative analysis of PSNR, SSIM and RMSE
Numerical solution of partial differential equations with MATLAB
地平线2022年4月最新方案介绍
Lambda表达式:一篇文章带你通透
20220524_ Database process_ Statement retention
STM32串口DAM接收253字节就死机原因排查
聊聊内存模型与内存序
LINQ usage collection in C #
潘多拉 IOT 开发板学习(HAL 库)—— 实验3 按键输入实验(学习笔记)

