package main
import (
"fmt"
)
func printArray(x [3]int) {
fmt.Printf("%d", x[1]);
// cannot convert "%d" (type untyped string) to type int
// invalid operation: "%d" + v (mismatched types string and int)
// for _, v := range x {
// fmt.Printf("%d" + v);
// }
}
func main() {
a := [3]int{1, 2, 3};
for _, v := range a {
fmt.Printf("%d
", v);
}
printArray(a);
}
I can successfully print the array in the go method, but when I pass array into the method, it throws an error when it tries to print. What cause's the method to treat it differently then main method?