Swap Two Values
Swap two variables using a temporary variable.
package main
import "fmt"
func main() {
a := "left"
b := "right"
fmt.Println("Before:", a, b)
temp := a
a = b
b = temp
fmt.Println("After:", a, b)
}Swap two variables using a temporary variable.
package main
import "fmt"
func main() {
a := "left"
b := "right"
fmt.Println("Before:", a, b)
temp := a
a = b
b = temp
fmt.Println("After:", a, b)
}Copy the code above and paste to run