zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    各种小知识
    基础技能
    st表
    有理数取余
    FFT加速高精度乘法
    unique
    离散化
    线段树复杂度分析
    楼房重建
    电脑装系统常用方法
  • 原文地址:https://www.cnblogs.com/cheyunhua/p/15713988.html
Copyright © 2011-2022 走看看