Skip to content

Instantly share code, notes, and snippets.

@lidaobing
Last active December 19, 2015 01:19
Show Gist options
  • Save lidaobing/5874584 to your computer and use it in GitHub Desktop.
Save lidaobing/5874584 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
)
type A struct {
I int
}
func foo1(a A) A {
return a
}
func foo2(a A) *A {
return &a
}
func foo3(a *A) *A {
return a
}
func foo4(a *A) A {
return *a
}
func main() {
a := A{1}
b := foo1(a)
c := foo2(a)
d := foo3(&a)
e := foo4(&a)
a.I = 2
fmt.Println("a.I", a.I, a)
fmt.Println("b.I", b.I, b)
fmt.Println("c.I", c.I, c)
fmt.Println("d.I", d.I, d)
fmt.Println("e.I", e.I, e)
}
$ go run 1.go
a.I 2 {2}
b.I 1 {1}
c.I 1 &{1}
d.I 2 &{2}
e.I 1 {1}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment