当前位置:网站首页>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])
}

边栏推荐
猜你喜欢
随机推荐
P1449 后缀表达式
[2022安恒夏令营] 5个小题
FinClip, help smart TV more imagination
2021年数据泄露成本报告解读
设置工作模式与环境(下):探查和收集信息
Three.js入门详解
Unity intercepts 3D images and the implementation of picture-in-picture PIP
Redis persistence method
leetcode/子串中不能有重复字符的最长子串
Shell编程之循环语句与函数
Flutter教程之为什么 Flutter 是创业的最佳选择?
rosbridge-WSL2 && carla-win11
Why Flutter Flutter of tutorials is the best choice for business?
智能管理PoE交换机
Use tf.image.resize() and tf.image.resize_with_pad() to resize images
直播系统聊天技术(八):vivo直播系统中IM消息模块的架构实践
HNUCM 2022年暑假ACM搜索专项练习
栈的压入、弹出序列
密码学基础以及完整加密通讯过程解析
Graph-node:创建一个新的subgraph









