How to pass map as function argument in Go

1 Answer

0 votes
package main
   
import "fmt"

func PrintMap(mp map[string]int) {
    for key, val := range mp {
        fmt.Println(key, "-", val)
    }
}
   
func main() {
    var mp = map[string]int{"go":35,"php":4, "c++":120, "python":8432}
      
    PrintMap(mp)
}
   
   
   
   
/*
run:
   
c++ - 120
python - 8432
go - 35
php - 4
   
*/

 



answered Nov 4, 2020 by avibootz

Related questions

1 answer 194 views
1 answer 181 views
3 answers 277 views
2 answers 159 views
...