Untitled
package main import "fmt" type person struct { age int name string } func showUser(p *person) { p.age = 35 p.name = "Alice" fmt.Println(*p) } func (p *person) changeUser() { p.age = 32 p.name = "Tom" // fmt.Println(p) } func main() { var user person = person{30, "Bob"} // fmt.Println(user) user.changeUser() fmt.Println(user) showUser(&user) }
Leave a Comment