当前位置:网站首页>2022-08-03:以下go语言代码输出什么?A:2;B:3;C:1;D:0。 package main import “fmt“ func main() { slice := []i
2022-08-03:以下go语言代码输出什么?A:2;B:3;C:1;D:0。 package main import “fmt“ func main() { slice := []i
2022-08-03 23:45:00 【福大大架构师每日一题】
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
- 并查集详解
- jav一键生成数据库文档
- 状态机实验
- 七夕活动浪漫上线,别让网络拖慢和小姐姐的开黑时间
- Flutter教程之为什么 Flutter 是创业的最佳选择?
- In V8 how arrays (with source code, picture and text easier to understand)
- 使用unbound在RHEL7上搭建DNS服务
- The super perfect layout has shortcut keys and background replacement
- vscode插件设置——Golang开发环境配置
猜你喜欢
Interpretation of ML: A case of global interpretation/local interpretation of EBC model interpretability based on titanic titanic rescued binary prediction data set using interpret
国内首发可视化智能调优平台,小龙带你玩转KeenTune UI
vscode插件设置——Golang开发环境配置
XSLT – 服务器端概述
Pytest learn-setup/teardown
In V8 how arrays (with source code, picture and text easier to understand)
【论文阅读】TRO 2021: Fail-Safe Motion Planning for Online Verification of Autonomous Vehicles Using Conve
3D 语义分割——2DPASS
FPGA按键消抖+蜂鸣器
Fluorescein-PEG-CLS,胆固醇-聚乙二醇-荧光素科研试剂
随机推荐
V8中的快慢数组(附源码、图文更易理解)
学习笔记 | uiautomation(如何)实现自动化
leetcode/子串中不能有重复字符的最长子串
用两个栈模拟队列
国内首发可视化智能调优平台,小龙带你玩转KeenTune UI
响应式织梦模板餐饮酒店类网站
【并发编程】ReentrantLock的lockInterruptibly()方法源码分析
Three.js入门详解
BPF 可移植性和 CO-RE(一次编译,到处运行)
Zilliz 2023 Fall Campus Recruitment Officially Launched!
最小化安装debian11
智能座舱的「交互设计」大战
电子邮件安全或面临新威胁!
设置工作模式与环境(下):探查和收集信息
P1996 约瑟夫问题
3D 语义分割——2DPASS
Scala basics [regular expressions, framework development principles]
二叉搜索树解决落叶问题
FinClip,助长智能电视更多想象空间
Go编译原理系列7(Go源码调试)