2022-10-31:以下go语言代码输出什么?A:map[];B:nil;C:Panic;D:编译错误。 package main import “fmt“ func main() {

2022-10-31:以下go语言代码输出什么?A:map[];B:nil;C:Panic;D:编译错误。

package main

import "fmt"

func main() {
    var m map[string]int
    delete(m, "oh noes!")
    fmt.Println(m)
}

答案选A。在 delete 函数的文档有说明:The delete built-in function deletes the element with the specified key (m[key]) from the map. If m is nil or there is no such element, delete is a no-op.这意思是没有元素的时候,啥都不做。
在这里插入图片描述

posted @   福大大架构师每日一题  阅读(10)  评论(0编辑  收藏  举报  
相关博文:
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· AI 智能体引爆开源社区「GitHub 热点速览」
· Manus的开源复刻OpenManus初探
· 写一个简单的SQL生成工具
历史上的今天:
2021-10-31 2021-10-31:移动零。给定一个数组 nums,编写一个函数将所有 0 移动到数组的末尾,同时保持非零元素的相对顺序。示例:输入: [0,1,0,3,12]。输出: [1,3,12,0,0]。说
点击右上角即可分享
微信分享提示