Program 1:
package main
import "fmt"
func main() {
CountryCode := make(map[int]string)
CountryCode["ind"] = 101
CountryCode["aus"] = 102
CountryCode["eng"] = 103
CountryCode["pak"] = 104
CountryCode["usa"] = 105
fmt.Println("India :", CountryCode["ind"])
fmt.Println("Australia:", CountryCode["aus"])
fmt.Println("England :", CountryCode["eng"])
fmt.Println("Pakistan :", CountryCode["pak"])
fmt.Println("USA :", CountryCode["usa"])
}
Program 2:
package main
import "fmt"
func main() {
CountryCode := make(map[string]int)
CountryCode.add("ind", 101)
CountryCode.add("aus", 102)
CountryCode.add("eng", 103)
CountryCode.add("pak", 104)
CountryCode.add("usa", 105)
fmt.Println("India :", CountryCode["ind"])
fmt.Println("Australia:", CountryCode["aus"])
fmt.Println("England :", CountryCode["eng"])
fmt.Println("Pakistan :", CountryCode["pak"])
fmt.Println("USA :", CountryCode["usa"])
}
Program 3:
package main
import "fmt"
func main() {
CountryCode := make(map[string]int)
CountryCode.insert("ind", 101)
CountryCode.insert("aus", 102)
CountryCode.insert("eng", 103)
CountryCode.insert("pak", 104)
CountryCode.insert("usa", 105)
fmt.Println("India :", CountryCode["ind"])
fmt.Println("Australia:", CountryCode["aus"])
fmt.Println("England :", CountryCode["eng"])
fmt.Println("Pakistan :", CountryCode["pak"])
fmt.Println("USA :", CountryCode["usa"])
}
Program 4:
package main
import "fmt"
func main() {
CountryCode := make(map[string]int)
CountryCode["ind"] = 101
CountryCode["aus"] = 102
CountryCode["eng"] = 103
CountryCode["pak"] = 104
CountryCode["usa"] = 105
delete(CountryCode, "pak")
fmt.Println("India :", CountryCode["ind"])
fmt.Println("Australia:", CountryCode["aus"])
fmt.Println("England :", CountryCode["eng"])
fmt.Println("Pakistan :", CountryCode["pak"])
fmt.Println("USA :", CountryCode["usa"])
}
Program 5:
package main
import "fmt"
func main() {
CountryCode := make(map[string]int)
CountryCode["ind"] = 101
CountryCode["aus"] = 102
CountryCode["eng"] = 103
CountryCode["pak"] = 104
CountryCode["usa"] = 105
var CloneMap = CountryCode.clone()
fmt.Println("CountryCode: ", CountryCode)
fmt.Println("CloneMap : ", CloneMap)
}
Answer Program 1:
Output:
Explanation:
The above program will generate syntax errors because we created the map with integer keys but we used string keys. We need to change on below line in the program,
CountryCode := make(map[string]int)
Answer Program 2:
Output:
Explanation:
The above program will generate syntax errors because add() function is not available in this context.
Answer Program 3:
Output:
Explanation:
The above program will generate syntax errors because the insert() function is not available in this context.
Answer Program 4:
Output:
Explanation:
In the above program, we created a map to store country codes. Then we added some country codes into the created map. After that, we removed an element from the map using the delete() function and printed the map elements.
Answer Program 5:
Output:
Explanation:
The above program will generate a syntax error because the clone() function is unavailable in this context.
The correct statement is given below,
var CloneMap = CountryCode
need an explanation for this answer? contact us directly to get an explanation for this answer