Advertisement
krovn

Untitled

Nov 20th, 2019
445
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 2.72 KB | None | 0 0
  1. func main() {
  2.     name := "John"                                                      // "John" is stored in address, and name is nickname of address
  3.     fmt.Print(name, " ("+reflect.TypeOf(name).String()+")\n")           // prints name's value and type of name
  4.     author := &name                                                     // takes name's address as value
  5.     fmt.Print(author, " ("+reflect.TypeOf(author).String()+")\n")       // prints author's value which is name's address and type of author
  6.     fmt.Println(&author)                                                // prints author's address
  7.     fmt.Println(*author)                                                // points to address' value
  8.     nametwo := &name                                                    // takes name's address as value
  9.     *nametwo = "Don"                                                    // points to address' value and changes it
  10.     fmt.Print(nametwo, " ("+reflect.TypeOf(nametwo).String()+")\n")     // prints nametwo's value which is name's address and type of nametwo
  11.     fmt.Println(author)                                                 // value doesnt change because name's address stays same.
  12.     fmt.Println(*author)                                                // points to address' value which is changed.
  13.     authortwo := &author                                                // takes author's address as value.
  14.     namethree := "Edgar"                                                // asigns new variable with type string
  15.     *authortwo = &namethree                                             // points to address' value and changes to take different address(namethree)
  16.     fmt.Print(authortwo, " ("+reflect.TypeOf(authortwo).String()+")\n") // prints authortwo's value and type of authortwo
  17.     fmt.Println(author)                                                 // prints author's value which is changed
  18.     fmt.Println(&namethree)                                             // prints namethree's address
  19.     fmt.Println(*author)                                                // points to address' value
  20.     kind := *author                                                     // asigns new variable with type strings and copies from namethree because its points to author's value's(address)
  21.     fmt.Print(kind, " ("+reflect.TypeOf(kind).String()+")\n")
  22.     //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
  23. }
  24. ============================================================
  25. John (string)
  26. 0xc0000581e0 (*string)
  27. 0xc00009a020
  28. John
  29. 0xc0000581e0 (*string)
  30. 0xc0000581e0
  31. Don
  32. 0xc00009a020 (**string)
  33. 0xc000058260
  34. 0xc000058260
  35. Edgar
  36. Edgar (string)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement