Neku's Blog

Go Pointer : Introduction

What I learned today about Go Pointer from Learning Go : Chapter 6 book :

var x *int 
fmt.Println(*x) // panics
var x = new(int)
fmt.Println(*x) // prints 0
x := &Foo{}
type Person struct {
    FirstName string
    LastName *string
}

p := person{
    FirstName: "Pat",
    LastName: &"Peterson", // This line won't compile
}
lastName := "Peterson"

p := person{
    FirstName: "Pat",
    LastName:  &lastName,
}