On Sat, Apr 20, 2019 at 11:10 PM <lgod...@gmail.com> wrote:
>
> Here's the snippet I'm trying to run
>
> package main
> import ( "fmt" )
>
> func main() {
>  Af(5)
> }
>
> func Af ( N int) {
>
> //var M = new([N][N]uint16)     !compiler error
> //var M = make([N][N]uint16)    !compiler error

The above two will not work. N needs to be a constant to declare an
array, here N is not a constant.

>
> //var M = make([][]uint16, N*N)  ##  run-time error

This is a slice of []uint16 with N*N elements. You never initialized
the elements of the array.

This should work:

https://play.golang.org/p/EABYHArTQ83

>
> // run-time error
>   M := make( [][]uint16, N*N,N*N)
>   for y:=0; y< N; y++ {
>     for x :=0; x< N; x++ {
>        M[y][x] = uint16(100*y +x)
>   }  }
>
>   for y :=0; y< N; y++ {
>       fmt.Printf("\n y= %3d", y )
>       for x :=0; x< N; x++ {
>            fmt.Printf(" %3d ", M[x][y] )
>   }   }
>  fmt.Printf("\n>>>>>>>>>>" )
> }
>
> --
> You received this message because you are subscribed to the Google Groups 
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to