Dynamically initialize array size in go

You should use a slice instead of an array:

//var array = new([elems]int) - no, arrays are not dynamic
var slice = make([]int,elems) // or slice := make([]int, elems)

See “go slices usage and internals”. Also you may want to consider using range for your loop:

// for i := 0; i < elems; i++ { - correct but less idiomatic
for i, v := range slice {

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)