当前位置:网站首页>2022-08-03:以下go语言代码输出什么?A:2;B:3;C:1;D:0。 package main import “fmt“ func main() { slice := []i
2022-08-03:以下go语言代码输出什么?A:2;B:3;C:1;D:0。 package main import “fmt“ func main() { slice := []i
2022-08-03 23:45:00 【福大大架构师每日一题】
2022-08-03:以下go语言代码输出什么?A:2;B:3;C:1;D:0。
package main
import "fmt"
func main() {
slice := []int{
0, 1, 2, 3}
m := make(map[int]*int)
for key, val := range slice {
m[key] = &val
}
fmt.Println(*m[2])
}
答案2022-08-03:
答案选B。val只会定义一次,等价于以下代码。
import (
"fmt"
)
func main() {
slice := []int{
0, 1, 2, 3}
m := make(map[int]*int)
key := 0
val := 0
for key < len(slice) {
val = slice[key]
m[key] = &val
key++
}
fmt.Println(*m[2])
}

边栏推荐
- 用两个栈模拟队列
- 【MySQL —— 索引】
- FPGA按键消抖+蜂鸣器
- IELTS essay writing template
- [Paper Reading] TRO 2021: Fail-Safe Motion Planning for Online Verification of Autonomous Vehicles Using Conve
- Why Flutter Flutter of tutorials is the best choice for business?
- 一文搞定 SQL Server 执行计划
- Creo 9.0二维草图的诊断:重叠几何
- ML之yellowbrick:基于titanic泰坦尼克是否获救二分类预测数据集利用yellowbrick对LoR逻辑回归模型实现可解释性(阈值图)案例
- The salary of soft testers at each stage, come to Kangkang, how much can you get?
猜你喜欢

ML之yellowbrick:基于titanic泰坦尼克是否获救二分类预测数据集利用yellowbrick对LoR逻辑回归模型实现可解释性(阈值图)案例

Minimized installation of debian11

vscode插件设置——Golang开发环境配置

跨域的学习

Scala基础【正则表达式、框架式开发原则】

Deep integration of OPC UA and IEC61499 (1)

2021年数据泄露成本报告解读

rosbridge-WSL2 && carla-win11

Creo 9.0二维草图的诊断:重叠几何

Jar a key generation document database
随机推荐
FinClip,助长智能电视更多想象空间
P1996 约瑟夫问题
我的祖国
Pytest learn-setup/teardown
BMN: Boundary-Matching Network for Temporal Action Proposal Generation Reading Notes
The curl using guide
P1449 后缀表达式
Jar a key generation document database
单例模式使用饿汉式和懒汉式创建一定安全?很多人不知
牛客2022 暑期多校3 H Hacker(SAM + 线段树查询区间内部最大子段和)
电子邮件安全或面临新威胁!
rsync 基础用法
学习笔记 | uiautomation(如何)实现自动化
The principle and use of AOSP CameraLatencyHistogram
跨域的学习
一文搞定 SQL Server 执行计划
The world's first mass production, with the most fixed points!How does this AVP Tier1 lead?
【OpenCV图像处理】 图像拼接技术
V8中的快慢数组(附源码、图文更易理解)
C语言实验十五 文件