当前位置:网站首页>一道golang中关于iota的面试题
一道golang中关于iota的面试题
2022-08-01 23:32:00 【youngqqcn】
请问以下程序运行输出什么?
package main
import "fmt"
const (
a = iota
b = iota
)
const (
name = "xxxx"
c = iota
d = iota
)
const a0 = iota
const (
a1 = iota
a2 = iota
a3 = 6
a4
a5 = iota
)
func main() {
fmt.Println(a)
fmt.Println(b)
fmt.Println(c)
fmt.Println(d)
fmt.Println(a1)
fmt.Println(a2)
fmt.Println(a3)
fmt.Println(a4)
fmt.Println(a5)
}
请思考,答案在下文。。。。。
。
。
。
。
。
。
。
。
。
。
。
。
0
1
1
2
0
1
6
6
4
iota
使用的规则如下:
- 每当
const
出现时, 都会使iota
初始化为0. const
中每新增一行常量声明将使iota
计数一次.
const (
a1 = iota // a1 = 0 // 又一个const出现, iota初始化为0
a2 = iota // a1 = 1 // const新增一行, iota 加1
a3 = 6 // a3 = 6 // 自定义一个常量
a4 // a4 = 6 // 不赋值就和上一行相同
a5 = iota // a5 = 4 // const已经新增了4行, 所以这里是4
)
边栏推荐
- PDF转Word有那么难吗?做一个文件转换器,都解决了
- color transparency parameter
- bat 之 特殊字符&转义
- ELK日志采集
- Chapter 11 Working with Dates and Times
- Loading configuration of Nacos configuration center
- perspectiveTransform warpPerspective getPerspectiveTransform findHomography
- E - Integer Sequence Fair
- 添加大量元素时使用 DocumentFragments
- cdh的hue上oozie启动报错,Cannot allocate containers as requested resource is greater than maximum allowed
猜你喜欢
仿牛客网项目第三章:开发社区核心功能(详细步骤和思路)
还在纠结报表工具的选型么?来看看这个
[LeetCode304 Weekly Competition] Two questions about the base ring tree 6134. Find the closest node to the given two nodes, 6135. The longest cycle in the graph
UML diagram of soft skills
drf生成序列化类代码
cdh的hue上oozie启动报错,Cannot allocate containers as requested resource is greater than maximum allowed
[Camp Experience Post] 2022 Cybersecurity Summer Camp
TCP 可靠吗?为什么?
数据增强--学习笔记(图像类,cnn)
Solve the port to take up
随机推荐
PostgreSQL 基础--常用命令
从0到100:招生报名小程序开发笔记
云原生DevOps环境搭建
drf生成序列化类代码
Interpretation of the paper (GSAT) "Interpretable and Generalizable Graph Learning via Stochastic Attention Mechanism"
Flink学习第四天——完成第一个Flink 流批一体案例
Flink学习第五天——Flink可视化控制台依赖配置和界面介绍
Flink学习第三天——一文带你了解什么是Flink流?
From 0 to 1: Design and R&D Notes of Graphic Voting Mini Program
ELK log collection
excel remove all carriage return from a cell
numpy.hstack
路径压缩、、
SQL Server (design database--stored procedure--trigger)
DRF generating serialization class code
qt-faststart 安装使用
Convert LocalDateTime to Date type
6133. 分组的最大数量
伸展树的特性及实现
How to better understand and do a good job?