Last active
October 20, 2022 06:01
-
-
Save hoangtuan151/8945058a93f94a42518ca74b7722e677 to your computer and use it in GitHub Desktop.
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
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