提交 14ca0bc3 编写于 作者: 麻凡_'s avatar 麻凡_

完成第大章

上级 c0eab71d
{
"type": "code_options",
"author": "dengmengmian",
"source": "array.md",
"notebook_enable": false
}
\ No newline at end of file
# 数组
关于数组,下面声明错误的是:
## 答案
```Go
var arr0 [3]int = [3]int{1, 2, 3, 4}
```
## 选项
### A
```Go
var arr0 [5]int = [5]int{1, 2, 3}
```
### B
```Go
a := [3]int{1, 2}
```
### C
```Go
b := [...]int{1, 2, 3, 4}
```
\ No newline at end of file
{
"type": "code_options",
"author": "dengmengmian",
"source": "arraycopy.md",
"notebook_enable": false
}
\ No newline at end of file
# 数组值拷贝
下面代码会输出什么?
```Go
func main() {
c := [3]int{1, 2, 3}
d := c
c[0] = 999
fmt.Println(d)
}
```
## 答案
[1, 2, 3]
## 选项
### A
编译报错
### B
[999, 2, 3]
### C
[2, 3]
\ No newline at end of file
{
"type": "code_options",
"author": "dengmengmian",
"source": "slice.md",
"notebook_enable": false
}
\ No newline at end of file
# 切片
下面代码会输出什么?
```Go
func main() {
s := []int{1, 2, 3} // len=3, cap=3
a := s
s[0] = 888
s = append(s, 4)
fmt.Println(a, len(a), cap(a)) // 输出:[888 2 3] 3 3
fmt.Println(s, len(s), cap(s)) // 输出:[888 2 3 4] 4 6
}
```
## 答案
`[1 2 3] 3 3``[1 2 3 4] 4 6`
## 选项
### A
`[888 2 3] 3 3``[888 2 3 4] 4 6`
### B
编译报错
### C
`[888 2 3] 3 3``[888 2 3 4] 3 3`
\ No newline at end of file
{
"type": "code_options",
"author": "dengmengmian",
"source": "map.md",
"notebook_enable": false
}
\ No newline at end of file
# map的初始化
下面代码运行是否会报错?
```Go
func main() {
var employeeSalary map[string]int
employeeSalary["steve"] = 12000
fmt.Println(employeeSalary)
}
```
## 答案
`assignment to entry in nil map`
## 选项
### A
输出 `nil`
### B
输出 `map[steve:12000]`
### C
输出 1200
{
"type": "code_options",
"author": "dengmengmian",
"source": "string.md",
"notebook_enable": false
}
\ No newline at end of file
# 字符串
以下go语言代码输出什么?
```Go
package main
import (
"fmt"
)
func main() {
num := 65
str := string(num)
fmt.Printf("%v, %T\n", str, str)
}
```
## 答案
`A, string`
## 选项
### A
`65, string`
### B
`65, int`
### C
编译报错
{
"type": "code_options",
"author": "dengmengmian",
"source": "fun.md",
"notebook_enable": false
}
\ No newline at end of file
# 函数的定义
```Go
func add(args ...int) int {
sum := 0
for _, arg := range args {
sum += arg
}
return sum
}
```
下面对add函数调用错误的是:
## 答案
`add([]int{1, 2})`
## 选项
### A
`add(1, 2)`
### B
`add(1, 3, 7)`
### C
`add([]int{1, 3, 7}...)`
{
"type": "code_options",
"author": "dengmengmian",
"source": "pointer.md",
"notebook_enable": false
}
\ No newline at end of file
# 指针语法
通过指针变量 p 访问其成员变量 name,下面语法正确的是:
## 答案
`(*p).name`
## 选项
### A
`&p.name`
### B
`(&p).name`
### C
`p->name`
{
"type": "code_options",
"author": "dengmengmian",
"source": "struct.md",
"notebook_enable": false
}
\ No newline at end of file
# 结构体的比较
关结构体的比较说法错误的是:
## 答案
切片、map、函数等类型结构体也是可以比较的
## 选项
### A
结构体之间只能比较它们是否相等,而不能比较它们的大小。
### B
只有所有属性都相等而属性顺序都一致的结构体才能进行比较。
### C
如果 struct 的所有成员都可以比较,则该 struct 就可以通过 == 或 != 进行比较是否相等,比较时逐个项进行比较,如果每一项都相等,则两个结构体才相等,否则不相等。
{
"type": "code_options",
"author": "dengmengmian",
"source": "fun.md",
"notebook_enable": false
}
\ No newline at end of file
# 方法的特性
以下关于方法特性错误的是:
## 答案
结构体方法名可以和字段重复
## 选项
### A
接收者可以同时为值和指针
### B
方法的声明和函数很相似, 只不过它必须指定接收者
### C
接收者定义的方法名不能重复。
{
"type": "code_options",
"author": "dengmengmian",
"source": "interface.md",
"notebook_enable": false
}
\ No newline at end of file
# 接口
关于接口下面说法错误的是:
## 答案
接口赋值是否可行,要在运行期才能够确定
## 选项
### A
接口查询是否成功,要在运行期才能够确定
### B
如果接口A的方法列表是接口B的方法列表的子集,那么接口B可以赋值给接口A
### C
只要两个接口拥有相同的方法列表(次序不同不要紧),那么它们就是等价的,可以相互赋值
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册