Pointers

Go has a pointer type which is similar to the one in C++.

/* * Go has a pointer type much like C++, except data allocated with new does * not need to be freed by the user. */ package main import "fmt" // Pointer parameter. Updates what p points to, but, of course // the variable sent to q is not changed. func stuff(p *int, q int) { *p += q; q = 99 } // A function that allocates and returns a pointer func maker(v int) *int { ret := new(int) *ret = v return ret } func main() { // C-ish pointer games. var q *int a := 10 q = &a *q += 3 // Some function things b := 15 stuff(&b, a) c := maker(30) fmt.Printf("%d %d %d\n", a, b, *c) }