Declare a pointer type with * operator

func foo() *string {} // returns a pointer to a string

Use the & operator to get the pointer of a value/struct.

var v int = 100
// we got a pointer to the value of v, also pt1 is of type pointer to int
var pt1 *int = &v

Use the * operator again, to “use” a pointer. When *someVariable is used, we’re modifying the underlying value by reference. If you don’t use the *, you update the pointer itself.

var v int = 100
var pt1 *int = &v
 
// Updating the value using *pt1
*pt1 = 200
fmt.Println("The updated value of variable v is =", v)
 
// Updating the pointer itself
var newV int = 300
pt1 = &newV
fmt.Println("The new value pt1 points to is =", *pt1)