interview-go icon indicating copy to clipboard operation
interview-go copied to clipboard

类似的题目不一样的答案

Open epolar opened this issue 3 years ago • 1 comments

题目一 题目二 位于q007和q014的这两个题目问题是一样的,但是答案不一样,q007的答案更为准确,将题目二的代码改成这样就可以正确运行:

type Student struct {
	Age int
}
func main() {
	kv := map[string]*Student{"menglu": {Age: 21}}
	kv["menglu"].Age = 22
	s := []Student{{Age: 21}}
	s[0].Age = 22
	fmt.Println(kv, s)
}

我在stackoverflow上找到了和q007类似的解答:https://stackoverflow.com/a/32751792/4737579

epolar avatar Aug 18 '21 02:08 epolar

这个说法貌似更能接受 @epolar

godaner avatar Sep 17 '21 09:09 godaner