A Tour of Go Nil slices

The zero value of a slice is nil.

A nil slice has a length and capacity of 0.

(To learn more about slices, read the Slices: usage and internalsarticle.)

复制代码
package main 
import "fmt"

func main() {
    var z []int
    fmt.Println(z, len(z), cap(z))
    if z == nil {
        fmt.Println("nil!")
    }
}
复制代码

 

posted @   wuhn  阅读(153)  评论(0编辑  收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示