2022-06-28:以下golang代码输出什么?A:true;B:false;C:panic;D:编译失败。 pa

2022-06-28:以下golang代码输出什么?A:true;B:false;C:panic;D:编译失败。

package main

import "fmt"

func main() {
    var p [100]int
    var m interface{} = [...]int{99: 0}
    fmt.Println(p == m)
}

答案2022-06-28:

答案选A。这道题以为选D,有点出乎意料。儿子属于老子,儿子们不属于老子们。只适合赋值,不适合比较。

A value x of non-interface type X and a value t of interface type T are comparable when values of type X are comparable and X implements T. They are equal if t’s dynamic type is identical to X and t’s dynamic value is equal to x. ——以上内容来自 go.dev/ref/spec#Operators

在这里插入图片描述

本作品采用《CC 协议》,转载必须注明作者和本文链接
微信公众号:福大大架构师每日一题。最新面试题,涉及golang,rust,mysql,redis,云原生,算法,分布式,网络,操作系统。
讨论数量: 1

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!
未填写
文章
471
粉丝
21
喜欢
37
收藏
22
排名:457
访问:1.9 万
私信
所有博文
社区赞助商