作者:SOCHUNGKWAN | 来源:互联网 | 2023-08-22 12:36
2023-01-09:以下go语言代码输出什么?A:+Inf;B:zero;C:somethingelse;D:doesn’tcompile。packagemainimport(
2023-01-09:以下go语言代码输出什么?A:+Inf; B:zero; C:something else; D:doesn’t compile。
package main
import (
"fmt"
"math"
)
func main() {
x := math.Inf(1)
switch {
case x < 0, x > 0:
fmt.Println(x)
case x == 0:
fmt.Println("zero")
default:
fmt.Println("something else")
}
}
答案选A。这道题考的不是语法,而是英语。根据注释 Inf returns positive infinity if sign >= 0, negative infinity if sign <0.,即可得出答案。