Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save shockalotti/6cbfc0aee8825bad168a to your computer and use it in GitHub Desktop.
Save shockalotti/6cbfc0aee8825bad168a to your computer and use it in GitHub Desktop.
Go Golang - pointers exercise, swap x and y
package main
import "fmt"
func swap(px, py *int) {
tempx := *px
tempy := *py
*px = tempy
*py = tempx
}
func main() {
x := int(1)
y := int(2)
fmt.Println("x was", x)
fmt.Println("y was", y)
swap(&x, &y)
fmt.Println("x is now", x)
fmt.Println("y is now", y)
}
@PureSoulShard
Copy link

Ty, bro for your useful code.
+1 STAR.

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