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

边栏推荐
- Fluorescein-PEG-CLS,胆固醇-聚乙二醇-荧光素科研试剂
- XSLT – 服务器端概述
- Another MySQL masterpiece published by Glacier (send the book at the end of the article)!!
- 【LeetCode】最长回文子序列(动态规划)
- 智能管理PoE交换机
- Shell 用法梳理总结
- ML's yellowbrick: A case of interpretability (threshold map) for LoR logistic regression model using yellowbrick based on whether Titanic was rescued or not based on the two-class prediction dataset
- Create function report error, prompting DECLARE definition syntax problem
- SPOJ 2774 Longest Common Substring(两串求公共子串 SAM)
- BPF 可移植性和 CO-RE(一次编译,到处运行)
猜你喜欢
随机推荐
The "interaction design" battle of the smart cockpit
Binary search tree to solve the fallen leaves problem
(PC+WAP)织梦模板不锈钢类网站
Pytest学习-skip/skipif
冰河又一MySQL力作出版(文末送书)!!
In V8 how arrays (with source code, picture and text easier to understand)
Pytest learn-setup/teardown
Creo 9.0在草图环境中创建坐标系
Three.js入门详解
2021年数据泄露成本报告解读
逆波兰表达式求值
栈的压入、弹出序列
Free自由协议系统开发
响应式织梦模板塑身瑜伽类网站
YOLOv7改进之二十二:涨点神器——引入递归门控卷积(gnConv)
P1996 约瑟夫问题
sqlnet.ora文件与连接认证方式的小测试
创建函数报错,提示DECLARE定义语法问题
2022/8/3 Exam Summary
最小化安装debian11









