Skip to content

Instantly share code, notes, and snippets.

@thekarel
Created March 28, 2015 10:36
Show Gist options
  • Save thekarel/25f23f03b7ba9ff97a25 to your computer and use it in GitHub Desktop.
Save thekarel/25f23f03b7ba9ff97a25 to your computer and use it in GitHub Desktop.
package main
import "fmt"
func swap(x, y *int) {
var z = *x
*x = *y
*y = z
}
func main() {
x := 3
y := 2
fmt.Println(x, y)
swap(&x, &y)
fmt.Println(x, y)
}
@lm913
Copy link

lm913 commented Dec 18, 2016

lines 6-8 can also be written as *x, *y = *y, *x

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment