Go Data Type Pointers swap two integers

Introduction

Program to swap two integers:


package main/*www .  ja v a 2s.  c o m*/

import "fmt"

func swap(x, y *int) { 
    *x, *y = *y, *x 
} 

func main(){
   a := 0
   b := 2
   
   swap(&a,&b)
   
   fmt.Println(a)
   fmt.Println(b)
}



PreviousNext

Related