Failed to pass parameter group by go?

I wrote the following code:

package main

import "fmt"

func modify(array [10]int){
    array[0] = 10
    fmt.Println("In modify(), array values:" , array)
}

func main() {
    array := [5]int{1,2,3,4,5}
    modify(array)

    fmt.Println("In main(), array values:" , array)
}

but compilation error:

main/define.go:12:8: cannot use array (type [5]int) as type [10]int in argument to modify

but I copied the sample code from the book. Could you tell me what went wrong?

clipboard.png

Jul.28,2021

you can replace [5] int {} with [10] int {}

Menu