Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
func printData(c chan *int) {
time.Sleep(time.Second * 3)
data := <-c
fmt.Println("Data in channel is: ", *data)
}
func main() {
fmt.Println("Main started...")
var a = 10
b := &a
//create channel
c := make(chan *int)
go printData(c)
fmt.Println("Value of b before putting into channel", *b)
c <- b
a = 20
fmt.Println("Updated value of a:", a)
fmt.Println("Updated value of b:", *b)
time.Sleep(time.Second * 2)
fmt.Println("Main ended...")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment