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.这意思是没有元素的时候,啥都不做。

go语言自定义类型的方法(以下go语言代码输出什么)(1)

,