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.這意思是沒有元素的時候,啥都不做。
更多精彩资讯请关注tft每日頭條,我们将持续为您更新最新资讯!