当前位置:网站首页>An interview question about iota in golang
An interview question about iota in golang
2022-08-01 23:36:00 【youngqqcn】
What is the output of the following program?
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 // define a constant
a4 // a4 = 6 // No assignment is the same as the previous line
a5 = iota // a5 = 4 // const已经新增了4行, 所以这里是4
)
边栏推荐
- 在CDH的hue上的oozie出现,提交 Coordinator My Schedule 时出错
- Dynamic Scene Deblurring with Parameter Selective Sharing and Nested Skip Connections
- npm npm
- Oracle database is set to read-only and read-write
- Department project source code sharing
- Leetcode 129求根节点到叶节点数字之和、104二叉树的最大深度、8字符串转换整数(atoi)、82删除排序链表中的重复元素II、204二分查找、94二叉树的中序遍历、144二叉树的前序遍历
- 研发团队数字化转型实践
- Convert LocalDateTime to Date type
- 对于在新标签页中打开的链接,始终使用“noopener”或“noreferrer”
- 问题解决方式了
猜你喜欢
随机推荐
分享10套开源免费的高品质源码,免费源码下载平台
数据增强--学习笔记(图像类,cnn)
研发团队数字化转型实践
ELK log collection
Chapter 19 Tips and Traps: Common Goofs for Novices
nodejs--process
最短路模板
excel change cell size
Oracle database is set to read-only and read-write
Chapter 11 Working with Dates and Times
6132. 使数组中所有元素都等于零-快速排序法
请问什么是 CICD
几道关于golang并发的面试题
经典文献阅读之--DLO
npm npm
D - Linear Probing- 并查集
毕业作业
Spark Sql之join on and和where
UML diagram of soft skills
How to better understand and do a good job?