Untitled

mail@pastecode.io avatar
unknown
golang
2 years ago
755 B
7
Indexable
Never
//0
var list []interface{}
var cars []Car
list = cars

//1
func main() {
    m := make(map[int]*int)
    const n = 3
    for i := 0; i < n; i++ {
    m[i] = &i
    }
    
    for _, v := range m {
    fmt.Println(*v) ??
    }
}



//2
func worker() chan int {
  ch := make(chan int)

  go func() {
   time.Sleep(3 * time.Second)
     fmt.Println("worker done")
   ch <- 42
  }()

  return ch
 }

 func main() {
  timeStart := time.Now()

   _, _ = <-worker(), <-worker()

  fmt.Println(int(time.Since(timeStart).Seconds()))
 }
 
 
 
 
//3
  func main() {
  v := 5
  p := &v
  fmt.Println(*p)

  changePointer(p)
  fmt.Println(*p)

 }

 func changePointer(p *int) {
  v := 3
  *p = v
 }