ref: 042d2992a8424c416efdfdbffc68d94e659ae1eb a-tour-of-go/basics/structs-slices-maps/1.3.4_struct-pointers.go -rw-r--r-- 396 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
24
/*
	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
	- You can obtain these from slice s with len(s) and cap(s)
*/

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)
}