当前位置:网站首页>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 intercepts 3D images and the implementation of picture-in-picture PIP
北京电竞元宇宙论坛活动顺利召开
1067 Sort with Swap(0, i)
3D Semantic Segmentation - 2DPASS
Creo9.0 绘制中心线
The Beijing E-sports Metaverse Forum was successfully held
curl使用指南
Creo 9.0二维草图的诊断:加亮开放端点
HNUCM 2022年暑假ACM搜索专项练习
Scala basics [regular expressions, framework development principles]
栈的压入、弹出序列
LeetCode 0155. 最小栈
V8中的快慢数组(附源码、图文更易理解)
"Miscellaneous" barcode by Excel as a string
用两个栈模拟队列
简单了解下 TCP,学习握手和挥手以及各种状态到底是怎么样的
vscode插件设置——Golang开发环境配置
Graph-node:创建一个新的subgraph
国内首发可视化智能调优平台,小龙带你玩转KeenTune UI
浅谈我国产业园区未来的发展方向









