Skip to content

Instantly share code, notes, and snippets.

@betandr
Last active July 18, 2019 11:36
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save betandr/38ed43925ba91cda99e57b40a6a89676 to your computer and use it in GitHub Desktop.
Pass by reference and value example
package main
import "fmt"
type T struct{ X int }
func inc1(t *T) {
t.X++
}
func inc2(t T) T {
return T{t.X + 1}
}
func main() {
var a = new(T)
var b = T{X: 0}
inc1(a)
b = inc2(b)
fmt.Println(a.X)
fmt.Println(b.X)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment