0

How to make a 2d slice with dynamic sizing?

Here, I created a 2d slice with a size of var m. This code gives a ERROR How to solve it? https://code.sololearn.com/cSEedWB60P0B/?ref=app

15th Aug 2021, 9:01 AM
˜”*°•.˜”*°• Mohan 333 •°*”˜.•°*”˜
˜”*°•.˜”*°• Mohan 333 •°*”˜.•°*”˜ - avatar
2 Respuestas
+ 3
˜”*°•.˜”*°• Mohan 333 •°*”˜.•°*”˜ You need to also initialize each slice of the 2d-slice: slice2d := make([][]int,m) for i:=0;i<m;i++{ slice2d[i] = make([]int,m) }
15th Aug 2021, 10:40 AM
Giorgos
+ 1
Giorgos D It really works! Thank you.
15th Aug 2021, 11:23 AM
˜”*°•.˜”*°• Mohan 333 •°*”˜.•°*”˜
˜”*°•.˜”*°• Mohan 333 •°*”˜.•°*”˜ - avatar