Tsallaka zuwa abun ciki
Justice Tech School

Pointers

& takes an address and * reads through a pointer. Pass a pointer to modify a value.

Example
package main

import "fmt"

func inc(n *int) { *n++ }

func main() {
	x := 5
	p := &x
	*p = 9
	fmt.Println(x, *p)
	inc(&x)
	fmt.Println(x)
}

Result

9 9
10

Exercise

Address of.

p := x

Quiz Test

Does Go have pointer arithmetic?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.