当前位置:网站首页>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])
}
边栏推荐
猜你喜欢
随机推荐
Flutter教程之为什么 Flutter 是创业的最佳选择?
数据分析知识点搜集(纯粹的搜集)
CAS: 178744-28-0, mPEG-DSPE, DSPE-mPEG, methoxy-polyethylene glycol-phosphatidylethanolamine supply
Shell编程之循环语句与函数
The super perfect layout has shortcut keys and background replacement
【LeetCode】最长公共子序列(动态规划)
设置工作模式与环境(下):探查和收集信息
Unity intercepts 3D images and the implementation of picture-in-picture PIP
The longest substring that cannot have repeating characters in a leetcode/substring
The Chinese Valentine's Day event is romantically launched, don't let the Internet slow down and miss the dark time
【论文阅读】TRO 2021: Fail-Safe Motion Planning for Online Verification of Autonomous Vehicles Using Conve
七夕?new一个对象
RSS订阅微信公众号初探-feed43
通过whl安装第三方包
The Beijing E-sports Metaverse Forum was successfully held
P1449 后缀表达式
MCS-51单片机,定时1分钟,汇编程序
689. 三个无重叠子数组的最大和
响应式织梦模板塑身瑜伽类网站
国内首发可视化智能调优平台,小龙带你玩转KeenTune UI