Values & References10 / 15
Up next

Swap via pointers

package main

import "fmt"

func swap(a, b *int) {
	*a, *b = *b, *a
}

func main() {
	x, y := 1, 2
	swap(&x, &y)
	fmt.Println(x, y) // 2 1
}
What you're solving

exchange two values through *