Last active
July 18, 2019 11:36
Star
You must be signed in to star a gist
Pass by reference and value example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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