Pointers

suggest change

A pointer to a variable is an address in memory of that variable.

Go doesn’t allow pointer arithmetic. You can’t add to or subtract from pointers.

Zero value of a pointer is nil.

Basics of pointers:

v := 5

// pv is a pointer to v
pv := &v
fmt.Printf("v: %d, pv: %p\n", v, pv)

// we change the value of v via pv
*pv = 4
fmt.Printf("v: %d\n", v)

// two pointers to the same value have the same address
pv2 := &v
fmt.Printf("pv: %p, pv2: %p\n", pv, pv2)
v: 5, pv: 0xc00007c010
v: 4
pv: 0xc00007c010, pv2: 0xc00007c010

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents