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

边栏推荐
- Code Casual Recording Notes_Dynamic Programming_416 Segmentation and Subsetting
- 【并发编程】ReentrantLock的lockInterruptibly()方法源码分析
- The Chinese Valentine's Day event is romantically launched, don't let the Internet slow down and miss the dark time
- 20年将投资美国约2000亿美元,三星电子财大气粗的样子真好看
- 密码学基础以及完整加密通讯过程解析
- rosbridge-WSL2 && carla-win11
- Creo 9.0二维草图的诊断:重叠几何
- 【职场杂谈】售前与销售工作配合探讨
- vscode插件设置——Golang开发环境配置
- 绕任意轴旋转矩阵推导
猜你喜欢
随机推荐
OPC UA 与IEC61499 深度融合(1)
密码学基础以及完整加密通讯过程解析
【杂项】如何将指定字体装入电脑然后能在Office软件里使用该字体?
Three.js入门详解
1067 Sort with Swap(0, i)
响应式织梦模板塑身瑜伽类网站
(PC+WAP)织梦模板不锈钢类网站
The "interaction design" battle of the smart cockpit
20年将投资美国约2000亿美元,三星电子财大气粗的样子真好看
现货白银需要注意八大事项
栈的压入、弹出序列
【OpenCV图像处理】 图像拼接技术
图论-虚拟节点分层建图
Deep integration of OPC UA and IEC61499 (1)
The Chinese Valentine's Day event is romantically launched, don't let the Internet slow down and miss the dark time
2021年数据泄露成本报告解读
【MySQL —— 索引】
Why Flutter Flutter of tutorials is the best choice for business?
RSS订阅微信公众号初探-feed43
代码重构:面向单元测试









