当前位置:网站首页>一道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
)
边栏推荐
猜你喜欢

Data Organization --- Chapter 5 Trees and Binary Trees --- The Concept of Binary Trees --- Application Questions

From 0 to 100: Notes on the Development of Enrollment Registration Mini Programs

6134. 找到离给定两个节点最近的节点-力扣双百代码

Sql之各种Join

C language - branch statement and loop statement

sys_kill系统调用

【参营经历贴】2022网安夏令营

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

Codeforces CodeTON Round 2 (Div. 1 + Div. 2, Rated, Prizes!) A-D 题解

sys_kill system call
随机推荐
添加大量元素时使用 DocumentFragments
计算两点之间的中点
From 0 to 100: Notes on the Development of Enrollment Registration Mini Programs
Avoid hidden text when loading fonts
What is CICD excuse me
excel change cell size
npm npm
中职网络安全竞赛B7比赛部署流程
[LeetCode304周赛] 两道关于基环树的题 6134. 找到离给定两个节点最近的节点,6135. 图中的最长环
Deep Learning Fundamentals - Numpy-based Recurrent Neural Network (RNN) implementation and backpropagation training
请问什么是 CICD
Department project source code sharing
CAKE:一个用于多视图知识图谱补全的可扩展性常识感知框架
Special characters & escapes in bat
excel split text into different rows
Chapter 11 Working with Dates and Times
D - Linear Probing- 并查集
chrome copies the base64 data of an image
Chapter 12 End-User Task As Shell Scripts
excel cell contian two words, seperated by a slash