ref: b10fb217bb6c0e0a4214a8d1e71e504481c0a13e a-tour-of-go/basics/structs-slices-maps/1.3.4_struct-pointers.go -rw-r--r-- 336 bytes View raw
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/*
	Notes 1.3.4

	- You can make struct pointers
	- We could write (*p).X to access the X field in the 'v' Vertex struct
	  Shorthand just uses the dot operator, removing the explicit dereference
*/

package main

import "fmt"

type Vertex struct {
	X int
	Y int
}

func main() {
	v := Vertex{1, 2}
	p := &v
	p.X = 1e9
	fmt.Println(v)
}