当前位置:网站首页>一道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
)
边栏推荐
- 深度学习基础-基于Numpy的循环神经网络(RNN)实现和反向传播训练
- IDEA入门看这一篇就够了
- 数据库表设计规则
- How do programmers solve online problems gracefully?
- CAKE:一个用于多视图知识图谱补全的可扩展性常识感知框架
- visual studio code multiple editing
- Thesis understanding [RL - Exp Replay] - Experience Replay with Likelihood-free Importance Weights
- When using DocumentFragments add a large number of elements
- Data Organization --- Chapter 5 Trees and Binary Trees --- The Concept of Binary Trees --- Application Questions
- 高效工作文档产出归类
猜你喜欢
sys_kill系统调用
From 0 to 100: Notes on the Development of Enrollment Registration Mini Programs
6134. Find the closest node to the given two nodes - force double hundred code
Spark Sql之join on and和where
[email protected]与
YOLO等目标检测模型的非极大值抑制NMS和评价指标(Acc, Precision, Recall, AP, mAP, RoI)、YOLOv5中[email protected]与
分享10套开源免费的高品质源码,免费源码下载平台
The monthly salary of the test post is 5-9k, how to increase the salary to 25k?
从0到100:招生报名小程序开发笔记
System availability: 3 9s, 4 9s in SRE's mouth... What is it?
研发团队数字化转型实践
随机推荐
计算由两点定义的线的角度
chrome复制一张图片的base64数据
【参营经历贴】2022网安夏令营
Check if point is inside rectangle
[C language advanced] file operation (2)
numpy.where
From 0 to 100: Notes on the Development of Enrollment Registration Mini Programs
2022/7/31
用virtualenv和Virtualenvwrapper虚拟环境管理工具创建虚拟环境
A. Doremy‘s IQ-- Codeforces Round #808 (Div. 1)
最短路模板
excel remove all carriage return from a cell
When using DocumentFragments add a large number of elements
cmd command
nodejs--process
访问控制台中的选定节点
对于在新标签页中打开的链接,始终使用“noopener”或“noreferrer”
Deep Learning Fundamentals - Numpy-based Recurrent Neural Network (RNN) implementation and backpropagation training
Interpretation of the paper (GSAT) "Interpretable and Generalizable Graph Learning via Stochastic Attention Mechanism"
伸展树的特性及实现