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.

Related questions

0 votes
asked Aug 11, 2022 in GoLang by SakshiSharma
0 votes
asked Aug 19, 2022 in GoLang by john ganales
...