Files
  • main.go
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package main

import "fmt"

// :show start
type Person struct {
	Name string
}

func main() {
	c := new(Person) // returns pointer
	c.Name = "Catherine"
	fmt.Println(c.Name) // prints: Catherine
	d := c
	d.Name = "Daniel"
	fmt.Println(c.Name) // prints: Daniel
	// Adding an Asterix before a pointer dereferences the pointer
	i := *d
	i.Name = "Ines"
	fmt.Println(c.Name) // prints: Daniel
	fmt.Println(d.Name) // prints: Daniel
	fmt.Println(i.Name) // prints: Ines
	// :show end
}
go version go1.9.4 linux/amd64