[Go] Package
2022-08-19:以下go语言代码输出什么?A:equal;B:not equal;C:不确定。 package main import ( “fmt“ “
2022-08-19:以下go语言代码输出什么?A:equal;B:not equal;C:不确定。package main import ( "fmt" "reflect" ) func main() { i := 1 j := 1 no1 := &i no2 := &j if r
日期 2023-06-12 10:48:402022-08-27:以下go语言代码输出什么?A:[0];B:panic;C:7;D:不清楚。 package main import ( “fmt“ ) f
2022-08-27:以下go语言代码输出什么?A:0;B:panic;C:7;D:不清楚。package main import ( "fmt" ) func main() { a := make([]int, 20) a = []int{7, 8, 9, 10} b := a[15:16] fmt.Println(b) }复制答案选B。a 被重新赋值
日期 2023-06-12 10:48:402022-09-06:以下go语言代码输出什么?A:Hi All;B:Hi go All;C:Hi;D:go All。 package main import
2022-09-06:以下go语言代码输出什么?A:Hi All;B:Hi go All;C:Hi;D:go All。package main import "fmt" func app() func(string) string { t := "Hi" c := func(b string) string { t = t
日期 2023-06-12 10:48:402022-09-12:以下go语言代码输出什么?A:true;B:false;C:无法编译;D:运行时 panic。 package main func mai
2022-09-12:以下go语言代码输出什么?A:true;B:false;C:无法编译;D:运行时 panic。package main func main() { var x chan<- chan error var y chan (<-chan error) println(x == y) }复制答案选C。这道题很多人选A。x和y的类型不一样。x里的元素是chan e
日期 2023-06-12 10:48:402022-09-14:以下go语言代码输出什么?A:0 0;B:0 1;C:1 1;D:1 0。 package main func main() { prin
2022-09-14:以下go语言代码输出什么?A:0 0;B:0 1;C:1 1;D:1 0。package main func main() { println(f(1)) } func f(x int) (_, __ int) { _, __ = x, x return }复制答案选B。单下划线只是占位的,不是变量;双下划线是变量。在这里插入图片描述
日期 2023-06-12 10:48:402022-09-20:以下go语言代码输出什么?A:8 8;B:8 16;C:16 16;D:16 8。 package main import ( “unsa
2022-09-20:以下go语言代码输出什么?A:8 8;B:8 16;C:16 16;D:16 8。package main import ( "unsafe" "fmt" ) func main() { type T1 struct { a struct{} x int64 }
日期 2023-06-12 10:48:402022-10-14:以下go语言代码输出什么?A:0;B:7;C:9;D:不能编译。 package main import “fmt“ func main(
2022-10-14:以下go语言代码输出什么?A:0;B:7;C:9;D:不能编译。package main import "fmt" func main() { a := []int{7, 8, 9} fmt.Println(a[real(2)]) }复制答案选C。go中slice的下标不能是浮点数,但real(2)是常量,所以是能编译通过的。在这里插入
日期 2023-06-12 10:48:402022-10-18:以下go语言代码输出什么?A:panic;B:编译错误;C:moonfdd1。 package main import ( “fmt“ “
2022-10-18:以下go语言代码输出什么?A:panic;B:编译错误;C:moonfdd1。package main import ( "fmt" "net/url" ) // 其中 url.Values 的定义:type Values map[string][]string type Query struct { url.Values }
日期 2023-06-12 10:48:402022-10-20:以下go语言代码输出什么?A:7;B:7.0;C:0;D:编译错误。 package main import ( “fmt“ ) func
2022-10-20:以下go语言代码输出什么?A:7;B:7.0;C:0;D:编译错误。package main import ( "fmt" ) func main() { const X = 7.0 var x interface{} = X if y, ok := x.(int); ok { fmt.Println(y) } else { fmt.
日期 2023-06-12 10:48:402022-10-24:以下go语言代码输出什么?A:3 3;B:3 4;C:0 0;D:0 1。 package main func main() { m :=
2022-10-24:以下go语言代码输出什么?A:3 3;B:3 4;C:0 0;D:0 1。package main func main() { m := make(map[int]int, 3) x := len(m) m[1] = m[1] y := len(m) println(x, y) }复制答案选D。这里关键是 m1 = m1,右边的 m1 返回 0(map
日期 2023-06-12 10:48:40Golang: Packages - Introduction
Packages - IntroductionEvery Go program is made up of packages.Note: Do not get confused with Go modules, which is Go’s dependency management system. A Go modules usually contains one or more Go packa
日期 2023-06-12 10:48:402022-07-26:以下go语言代码输出什么?A:5;B:hello;C:编译错误;D:运行错误。package mainim
2022-07-26:以下go语言代码输出什么?A:5;B:hello;C:编译错误;D:运行错误。package main import ( "fmt" ) type integer int func (i integer) String() string { return "hello" } func main() { fmt.Pri
日期 2023-06-12 10:48:402022-08-21:以下go语言代码输出什么?A:0;B:panic;C:不知道。package mainvar n = -9
2022-08-21:以下go语言代码输出什么?A:0;B:panic;C:不知道。package main var n = -99 func main() { m := make(map[string]int, n) println(m["Go"]) }复制答案选A。从 map 获取数据,即使 map 是 nil,也不会 panic。通过 make 创建 map
日期 2023-06-12 10:48:402022-09-08:以下go语言代码输出什么?A:5 66;B:5 88;C:7 88;D:以上都不对。package mai
2022-09-08:以下go语言代码输出什么?A:5 66;B:5 88;C:7 88;D:以上都不对。package main func main() { var x = []int{4:44, 55, 66, 1:77, 88} println(len(x), x[2]) }复制答案2022-09-08:答案选A。x是[0 77 88 0 44 55 66],答案显而易见。
日期 2023-06-12 10:48:402022-10-02:以下go语言代码能否通过编译?A: 能;B: 不能;C: 不知道。package mainimport (
2022-10-02:以下go语言代码能否通过编译?A: 能;B: 不能;C: 不知道。package main import ( "fmt" ) type worker interface { work() } type person struct { name string worker } func main() { var
日期 2023-06-12 10:48:402022-10-08:以下go语言代码输出什么?A、0 0;B、0 4;C:4 0;D:4 4。package maincons
2022-10-08:以下go语言代码输出什么?A、0 0;B、0 4;C:4 0;D:4 4。package main const s = "Go101.org" // len(s) == 9 // 1 << 9 == 512 // 512 / 128 == 4 var a byte = 1 << len(s) / 128 var b byte =
日期 2023-06-12 10:48:402022-10-18:以下go语言代码输出什么?A:panic;B:编译错误;C:moonfdd1。package mainim
2022-10-18:以下go语言代码输出什么?A:panic;B:编译错误;C:moonfdd1。package main import ( "fmt" "net/url" ) // 其中 url.Values 的定义:type Values map[string][]string type Query struct { url.Value
日期 2023-06-12 10:48:40Go语言中常见100问题-#14 Ignoring package name collisions
忽视包名冲突当变量名与包名相同时会发生包冲突,会阻止包被重用。下面来看一个Redis客户端库的具体例子。package redis type Client struct { ... } func NewClient() *Client { ... } func (c *Client) Get(key string) (string, error) { ... } 复制上述代码保存在re
日期 2023-06-12 10:48:40解决Resource doesn't have a corresponding Go package.问题
首先上图 这个报错主要是程序要启动没有入口的原因,package main下边的mian方法才是一个程序的入口。这就要 修改目录结构如下图修改并运行就可以了
日期 2023-06-12 10:48:40go install -v github.com/gopherjs/gopherjs报错提示go cannot find package "golang.org/x/crypto/ssh/terminal" 解决方案
1前言 方法一:go get 方法二: github clone 2 方法方法一:go get go get golang.org/x/crypto/ssh/terminal 但是这种方法容易被墙,出现如下错误: package golang.org/x/crypto/ssh/terminal: unrecognized import path “golang.org/x/cry
日期 2023-06-12 10:48:40