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

C#大型互联网平台管理框架源码:基于ASP.NET MVC+EF6+Bootstrap开发,支持多数据库

软技能之UML图

仿牛客网项目第三章:开发社区核心功能(详细步骤和思路)

中职网络安全竞赛B7比赛部署流程

drf生成序列化类代码

Deep Learning Fundamentals - Numpy-based Recurrent Neural Network (RNN) implementation and backpropagation training
![[LeetCode304周赛] 两道关于基环树的题 6134. 找到离给定两个节点最近的节点,6135. 图中的最长环](/img/63/16de443caf28644d79dc6e6889e5dd.png)
[LeetCode304周赛] 两道关于基环树的题 6134. 找到离给定两个节点最近的节点,6135. 图中的最长环

From 0 to 1: Design and R&D Notes of Graphic Voting Mini Program

程序员如何优雅地解决线上问题?

在CDH的hue上的oozie出现,提交 Coordinator My Schedule 时出错
随机推荐
Nacos配置中心之加载配置
Is TCP reliable?Why?
excel split text into different rows
访问控制台中的选定节点
Chapter 19 Tips and Traps: Common Goofs for Novices
CF1705D Mark and Lightbulbs
怎样做才能让这条SQL变成一条危险的SQL?
LocalDateTime转为Date类型
6132. All the elements in the array is equal to zero - quick sort method
PDF转Word有那么难吗?做一个文件转换器,都解决了
chrome复制一张图片的base64数据
Deep Learning Fundamentals - Numpy-based Recurrent Neural Network (RNN) implementation and backpropagation training
Building a cloud-native DevOps environment
How to better understand and do a good job?
Getting started with IDEA is enough to read this article
cmd指令
Special characters & escapes in bat
还在纠结报表工具的选型么?来看看这个
6133. Maximum number of packets
数据库表设计规则