0%
下面代码的输出是什么(判断 a == b )的部分?为什么?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| func main() {
a := &struct{}{} b := &struct{}{}
fmt.Printf("%p\n", a) fmt.Printf("%p\n", b)
fmt.Printf("%p\n", &a) fmt.Printf("%p\n", &b)
fmt.Println(a == b) }
|
引申 切片的引用
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| func main() { a := make([]byte, 100) b := a
a[10] = 'y' b[10] = 'x'
fmt.Println("a[10] =", a[10]) fmt.Println("b[10] =", b[10])
c := [3]byte{1, 2, 3} d := c
c[2] = 'x' d[2] = 'y' fmt.Println("c[2] =", c[2]) fmt.Println("d[2] =", d[2])
g := c[:] h := g
g[2] = 'x' h[2] = 'y'
fmt.Println("g[2] = ", g[2]) fmt.Println("h[2] = ", h[2]) }
|