当前位置:网站首页>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
)
边栏推荐
- Data Organization --- Chapter 5 Trees and Binary Trees --- The Concept of Binary Trees --- Application Questions
- 问题解决方式了
- 6132. All the elements in the array is equal to zero - quick sort method
- 解决端口占用
- TCP 可靠吗?为什么?
- 毕业作业
- 研发团队数字化转型实践
- 6133. 分组的最大数量
- Chapter 19 Tips and Traps: Common Goofs for Novices
- 中职网络安全竞赛B7比赛部署流程
猜你喜欢
![[LeetCode304周赛] 两道关于基环树的题 6134. 找到离给定两个节点最近的节点,6135. 图中的最长环](/img/63/16de443caf28644d79dc6e6889e5dd.png)
[LeetCode304周赛] 两道关于基环树的题 6134. 找到离给定两个节点最近的节点,6135. 图中的最长环

邻接表与邻接矩阵

CAKE:一个用于多视图知识图谱补全的可扩展性常识感知框架

在CDH的hue上的oozie出现,提交 Coordinator My Schedule 时出错

TCP 可靠吗?为什么?

获取小猪民宿(短租)数据

chrome复制一张图片的base64数据

The monthly salary of the test post is 5-9k, how to increase the salary to 25k?

数据增强--学习笔记(图像类,cnn)

What is CICD excuse me
随机推荐
软技能之UML图
Flink学习第三天——一文带你了解什么是Flink流?
problem solved
如何更好的理解的和做好工作?
PostgreSQL 基础--常用命令
Building a cloud-native DevOps environment
cdh的hue上oozie启动报错,Cannot allocate containers as requested resource is greater than maximum allowed
sys_kill系统调用
系统可用性:SRE口中的3个9,4个9...到底是个什么东西?
numpy.hstack
Quartus 使用 tcl 文件快速配置管脚
bat 之 特殊字符&转义
Leetcode 129求根节点到叶节点数字之和、104二叉树的最大深度、8字符串转换整数(atoi)、82删除排序链表中的重复元素II、204二分查找、94二叉树的中序遍历、144二叉树的前序遍历
解决端口占用
软件测试之移动APP安全测试简析,北京第三方软件检测机构分享
6134. 找到离给定两个节点最近的节点-力扣双百代码
萍不回答
Data Organization --- Chapter 5 Trees and Binary Trees --- The Concept of Binary Trees --- Application Questions
excel split text into different rows
D - Linear Probing- 并查集