your printArray(my_arr []int) function's parameter expecting a slice, not an array.
In Go, from syntax [...]{1,2,3} creating an array with number of elements in the brackets.
NOTE: If you have not any use case specially with an array, please use @inian's answer.
So in this case, there is two ways to do this.
1st way
- send slice to print from the array
package main
import "fmt"
func printArray(my_arr []int) {
fmt.Println(len(my_arr))
}
func main() {
arr := [...]int{17, -22, 15, 20, 33, 25, 22, 19}
printArray(arr[:])
}
2nd way
- accept array in
printArray function.
- but this has some limitation, it will accept arrays with the one length. In this case it is 8.
package main
import "fmt"
func printArray(my_arr [8]int) {
fmt.Println(len(my_arr))
}
func main() {
arr := [...]int{17, -22, 15, 20, 33, 25, 22, 19}
printArray(arr)
}