Go 語言複製指針的值

Go 語言複製指針的值可以通過 *copy = *pointer 完成。

package main

import "fmt"

type person struct {
    name string
    gender int
}

func main() {
    foo := &person{"foo", 1}
    bar := &person{}
    *bar = *foo
    fmt.Println(foo, bar)

    bar.name = "bar"
    fmt.Println(foo, bar)
}
$ go run main.go
&{foo 1} &{foo 1}
&{foo 1} &{bar 1}