Skip to content

Instantly share code, notes, and snippets.

@hoangtuan151
Last active October 20, 2022 06:01
Show Gist options
  • Save hoangtuan151/8945058a93f94a42518ca74b7722e677 to your computer and use it in GitHub Desktop.
Save hoangtuan151/8945058a93f94a42518ca74b7722e677 to your computer and use it in GitHub Desktop.
type Student struct {
Name string
}
func (s Student) Display(prefix string) {
fmt.Printf("[%s] I'm %s\n", prefix, s.Name)
}
func ChangeStudentV3(s *Student) {
// s.Name = "Kane"
s = &Student{"new name"}
s.Display("Func")
}
func main() {
s := Student{"Joe"}
s.Display("Main")
ChangeStudentV3(&s)
s.Display("Main")
}
====== OUTPUT ======
[Main] I'm Joe
[Func] I'm new name
[Main] I'm Joe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment