0 votes
in GoLang by
Swap the values of two variables without a temporary variable

1 Answer

0 votes
by

Implement swap() which swaps the value of two variables without using a third variable.

Solution

package main

import "fmt"

func main() {

   fmt.Println(swap())

}

func swap() []int {

      a, b := 15, 10

Run

While this may be tricky in other languages, Go makes it easy.

We can simply include the statement b, a = a, b, what data the variable references without engaging with either value.

...