当前位置:网站首页>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
)
边栏推荐
- cmd command
- Deep Learning Fundamentals - Numpy-based Recurrent Neural Network (RNN) implementation and backpropagation training
- 请问什么是 CICD
- CF1705D Mark and Lightbulbs
- When using DocumentFragments add a large number of elements
- cmd指令
- sys_kill系统调用
- Getting started with IDEA is enough to read this article
- 递归:方法调用自身
- CAKE:一个用于多视图知识图谱补全的可扩展性常识感知框架
猜你喜欢

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

Sql之各种Join

Spark Sql之join on and和where

Secondary Vocational Network Security Competition B7 Competition Deployment Process

CDH6的Hue打开出现‘ascii‘ codec can‘t encode characters

企业防护墙管理,有什么防火墙管理工具?

云原生DevOps环境搭建

经典文献阅读之--DLO

C language - branch statement and loop statement

cmd指令
随机推荐
cmd指令
Spark Sql之union
Leetcode 129求根节点到叶节点数字之和、104二叉树的最大深度、8字符串转换整数(atoi)、82删除排序链表中的重复元素II、204二分查找、94二叉树的中序遍历、144二叉树的前序遍历
y84. Chapter 4 Prometheus Factory Monitoring System and Actual Combat -- Advanced Prometheus Alarm Mechanism (15)
Sql之各种Join
PostgreSQL Basics--Common Commands
npm npm
Always use "noopener" or "noreferrer" for links that open in a new tab
递归:方法调用自身
Dynamic Scene Deblurring with Parameter Selective Sharing and Nested Skip Connections
Calculate the angle of a line defined by two points
Is TCP reliable?Why?
Chapter 12 End-User Task As Shell Scripts
Oracle 数据库设置为只读及读写
[LeetCode304 Weekly Competition] Two questions about the base ring tree 6134. Find the closest node to the given two nodes, 6135. The longest cycle in the graph
Building a cloud-native DevOps environment
部门项目源码分享
数据增强--学习笔记(图像类,cnn)
萍不回答
IDEA common plugins