This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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