go类型的默认值,注意pointer, channel, func, interface, map, or slice在没初始化的情况下

nil is a predeclared identifier representing the zero value for a pointer, channel, func, interface, map, or slice type.
Type must be a pointer, channel, func, interface, map, or slice type



package main

import "fmt"



func main() {
var slic []string
var m map[string]interface{}
var i interface{}
var ptr *int
var c chan string
var f func()
var s *struct{}
fmt.Println(slic,m,i,ptr,c,f,s)
if slic == nil{
fmt.Println("true")
}
if m == nil{
fmt.Println("true")
}


}
//reset

[] map[] <nil> <nil> <nil> <nil> <nil>
true
true

进程 已完成,退出代码为 0

原文地址:https://www.cnblogs.com/cheyunhua/p/15713988.html