当前位置:网站首页>June 22, 2022: golang multiple choice question, what does the following golang code output? A:3; B:1; C:4; D: Compilation failed. package main import ( “fmt“ ) func mai

June 22, 2022: golang multiple choice question, what does the following golang code output? A:3; B:1; C:4; D: Compilation failed. package main import ( “fmt“ ) func mai

2022-06-23 05:40:00 Fuda scaffold constructor's daily question

2022-06-22:golang choice question , following golang What does the code output ?A:3;B:1;C:4;D: Compile failed .

package main

import (
    "fmt"
)

func main() {
    
    var nums1 []interface{
    }
    nums2 := []int{
    1, 3, 4}
    nums3 := append(nums1, nums2...)
    fmt.Println(len(nums3))
}

answer 2022-06-22:

Answer selection D. Compiler error cannot use nums2 (type []int) as type []interface {} in append.int Belong to interface{},[]int Do not belong to []interface{}. Son belongs to Lao Tzu , Sons do not belong to Lao Tzu .

 Insert picture description here

原网站

版权声明
本文为[Fuda scaffold constructor's daily question]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/174/202206230119256084.html