当前位置:网站首页>2022-08-03: What does the following go code output?A: 2; B: 3; C: 1; D: 0.package main import "fmt" func main() { slice := []i
2022-08-03: What does the following go code output?A: 2; B: 3; C: 1; D: 0.package main import "fmt" func main() { slice := []i
2022-08-03 23:53:00 【F greatly architects of the day】
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])
}

边栏推荐
- Unity 截取3D图像 与 画中画PIP的实现
- Prometheus监控Harbor(二进制版)
- [Paper Reading] TRO 2021: Fail-Safe Motion Planning for Online Verification of Autonomous Vehicles Using Conve
- Install third-party packages via whl
- Read FastDFS in one article
- 绕任意轴旋转矩阵推导
- Creo 9.0二维草图的诊断:着色封闭环
- 重新认识浏览器的渲染过程
- JVM垃圾回收总结(未完待续)
- 免费的公共WiFi不要乱连,遭中间人攻击了吧?
猜你喜欢
随机推荐
Unity 截取3D图像 与 画中画PIP的实现
孙宇晨受邀参加36氪元宇宙峰会并发表主题演讲
YOLOv7改进之二十二:涨点神器——引入递归门控卷积(gnConv)
用队列模拟实现栈
FPGA按键消抖+蜂鸣器
直播系统聊天技术(八):vivo直播系统中IM消息模块的架构实践
Zilliz 2023 Fall Campus Recruitment Officially Launched!
HNUCM 您好中国
OPC UA 与IEC61499 深度融合(1)
用栈实现队列
Jar a key generation document database
SPOJ 2774 Longest Common Substring(两串求公共子串 SAM)
IELTS essay writing template
Read FastDFS in one article
小身材有大作用——光模块寿命分析(二)
单例模式使用饿汉式和懒汉式创建一定安全?很多人不知
Minimized installation of debian11
In V8 how arrays (with source code, picture and text easier to understand)
Redis persistence method
学习笔记 | uiautomation(如何)实现自动化









