Advertisement
Guest User

Untitled

a guest
Aug 28th, 2015
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4. "fmt"
  5. "unsafe"
  6. )
  7.  
  8. type user struct {
  9. name string
  10. email string
  11. }
  12.  
  13. func (u user) notify() {
  14. fmt.Printf("Address in Value Receiver %vn", unsafe.Pointer(&u))
  15. fmt.Printf(" Sending %s an email at %sn", u.name, u.email)
  16. }
  17.  
  18. func (u *user) changeEmail(email string) {
  19. fmt.Printf("Address in Pointer Receiver %vn", unsafe.Pointer(&u))
  20. u.email = email
  21. }
  22.  
  23. func main() {
  24. u := user{
  25. name: "mike",
  26. email: "mike@gmail.com",
  27. }
  28. fmt.Printf("Address in Main %vn", unsafe.Pointer(&u))
  29. u.notify()
  30. u.changeEmail("john@gmail.com")
  31. u.notify()
  32. }
  33.  
  34. Address in Main **0x2081a0020**
  35. Address in Value Receiver 0x2081a0060
  36. Sending mike an email at mike@gmail.com
  37. Address in Pointer Receiver **0x2081cc020**
  38. Address in Value Receiver 0x2081a0080
  39. Sending mike an email at john@gmail.com
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement