Example: #1 - Swapping of two numbers using temporary variable
Golang Input Screen
package main
import (
"fmt"
"strconv"
)
func main() {
var a int = 3
var b int = 6
fmt.Println("The value of a before swap is " + strconv.Itoa(a))
fmt.Println("The value of b before swap is " + strconv.Itoa(b))
// Swapping of two numbers using temp variable
var temp int = a
a = b
b = temp
fmt.Println("The value of a after swap is " + strconv.Itoa(a))
fmt.Println("The value of b after swap is " + strconv.Itoa(b))
}
Golang Output Screen
The value of a before swap is 3
The value of b before swap is 6
The value of a after swap is 6
The value of b after swap is 3