Advertisement
Guest User

Untitled

a guest
Oct 19th, 2019
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.57 KB | None | 0 0
  1. func main() {
  2.     // I thought 'person' would have been a memory address?
  3.     person := &Person{
  4.         FirstName: "John",
  5.         LastName:  "Doe",
  6.     }
  7.  
  8.     // Both lines print the same value
  9.     fmt.Printf("person: %#v\n", person)
  10.     fmt.Printf("person: %#v\n", *person)
  11.  
  12.     // I create a new string variable
  13.     variable := "Hello world"
  14.  
  15.     // Assign its memory address to 'pointer' which is what I thought I was doing with 'person'
  16.     pointer := &variable
  17.  
  18.     // Printing 'pointer' prints the memory address and printing '*pointer' prints the value store at that address
  19.     fmt.Println(*pointer)
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement