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() {](https://static001.geekbang.org/infoq/d9/d9db4e133ecefbc917222ff6c36886fd.png)
2022-10-31:以下 go 语言代码输出什么?A:map[];B:nil;C:Panic;D:编译错误。
复制代码
答案选 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.这意思是没有元素的时候,啥都不做。

版权声明: 本文为 InfoQ 作者【福大大架构师每日一题】的原创文章。
原文链接:【http://xie.infoq.cn/article/04338ccfad987d67426e706c2】。
本文遵守【CC-BY 4.0】协议,转载请保留原文出处及本版权声明。
评论