Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "fmt"
- "unsafe"
- )
- type user struct {
- name string
- email string
- }
- func (u user) notify() {
- fmt.Printf("Address in Value Receiver %vn", unsafe.Pointer(&u))
- fmt.Printf(" Sending %s an email at %sn", u.name, u.email)
- }
- func (u *user) changeEmail(email string) {
- fmt.Printf("Address in Pointer Receiver %vn", unsafe.Pointer(&u))
- u.email = email
- }
- func main() {
- u := user{
- name: "mike",
- email: "mike@gmail.com",
- }
- fmt.Printf("Address in Main %vn", unsafe.Pointer(&u))
- u.notify()
- u.changeEmail("john@gmail.com")
- u.notify()
- }
- Address in Main **0x2081a0020**
- Address in Value Receiver 0x2081a0060
- Sending mike an email at mike@gmail.com
- Address in Pointer Receiver **0x2081cc020**
- Address in Value Receiver 0x2081a0080
- Sending mike an email at john@gmail.com
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement