当前位置:网站首页>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])
}
边栏推荐
猜你喜欢
Creo 9.0二维草图的诊断:加亮开放端点
用栈实现队列
Three.js入门详解
Graph-node:创建一个新的subgraph
利用matlab求解线性优化问题【基于matlab的动力学模型学习笔记_11】
智能座舱的「交互设计」大战
汉字风格迁移---结合本地和全局特征学习的中文字体迁移
The super perfect layout has shortcut keys and background replacement
Code Casual Recording Notes_Dynamic Programming_416 Segmentation and Subsetting
POE交换机全方位解读(上)
随机推荐
The "interaction design" battle of the smart cockpit
浅谈我国产业园区未来的发展方向
孙宇晨受邀参加36氪元宇宙峰会并发表主题演讲
rosbridge-WSL2 && carla-win11
Creo9.0 绘制中心线
Redis persistence method
现货白银需要注意八大事项
MCS-51单片机,定时1分钟,汇编程序
Zilliz 2023 Fall Campus Recruitment Officially Launched!
Use tf.image.resize() and tf.image.resize_with_pad() to resize images
OpenCV 图像拼接
curl使用指南
[2022强网杯] polydiv和gamemaster
2022-08-03:以下go语言代码输出什么?A:2;B:3;C:1;D:0。 package main import “fmt“ func main() { slice := []i
Minimized installation of debian11
rsync basic usage
【每日一题】899. 有序队列
数据分析知识点搜集(纯粹的搜集)
使用unbound在RHEL7上搭建DNS服务
P1996 约瑟夫问题