Skip to content

Instantly share code, notes, and snippets.

@YanhaoYang
Created June 25, 2017 14:57
Show Gist options
  • Save YanhaoYang/a2297f271b8933a8a71154f78b49b42f to your computer and use it in GitHub Desktop.
Save YanhaoYang/a2297f271b8933a8a71154f78b49b42f to your computer and use it in GitHub Desktop.
golang-struct-copy-is-memory-copy
package main
import (
"fmt"
)
type A struct {
S1 string
}
type B struct {
Apt *A
S2 string
}
func main() {
b1 := B{Apt: &A{S1: "hi"}, S2: "h2"}
b2 := b1
b2.Apt.S1 = "haha"
b2.S2 = "ha2"
fmt.Println(b1, b2, b1.Apt, b2.Apt)
}
// https://play.golang.org/p/UhdzGKz-s0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment