Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- func main() {
- name := "John" // "John" is stored in address, and name is nickname of address
- fmt.Print(name, " ("+reflect.TypeOf(name).String()+")\n") // prints name's value and type of name
- author := &name // takes name's address as value
- fmt.Print(author, " ("+reflect.TypeOf(author).String()+")\n") // prints author's value which is name's address and type of author
- fmt.Println(&author) // prints author's address
- fmt.Println(*author) // points to address' value
- nametwo := &name // takes name's address as value
- *nametwo = "Don" // points to address' value and changes it
- fmt.Print(nametwo, " ("+reflect.TypeOf(nametwo).String()+")\n") // prints nametwo's value which is name's address and type of nametwo
- fmt.Println(author) // value doesnt change because name's address stays same.
- fmt.Println(*author) // points to address' value which is changed.
- authortwo := &author // takes author's address as value.
- namethree := "Edgar" // asigns new variable with type string
- *authortwo = &namethree // points to address' value and changes to take different address(namethree)
- fmt.Print(authortwo, " ("+reflect.TypeOf(authortwo).String()+")\n") // prints authortwo's value and type of authortwo
- fmt.Println(author) // prints author's value which is changed
- fmt.Println(&namethree) // prints namethree's address
- fmt.Println(*author) // points to address' value
- kind := *author // asigns new variable with type strings and copies from namethree because its points to author's value's(address)
- fmt.Print(kind, " ("+reflect.TypeOf(kind).String()+")\n")
- //fmt.Println(*kind) cant because kind's value is not address and it doesnt have type pointer instead its copied string and had type assign string
- }
- ============================================================
- John (string)
- 0xc0000581e0 (*string)
- 0xc00009a020
- John
- 0xc0000581e0 (*string)
- 0xc0000581e0
- Don
- 0xc00009a020 (**string)
- 0xc000058260
- 0xc000058260
- Edgar
- Edgar (string)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement