I am using following simple code for 2d array in golang, where APPEND function is resulting in Duplicate values rather than appending.
package main
import "fmt"
func main() {
var n int
fmt.Scanf("%d", &n)
array := [][]int{}
row := make([]int, n)
for _, _ = range row {
for j, _ := range row {
fmt.Scanf("%d", &row[j])
}
fmt.Println("Printing current Row", row)
array = append(array, row)
fmt.Println("Printing curent Array", array)
}
fmt.Println("Final Array", array)
}
But Strangely this are not going unexpectedly. If suppose i want this thing to happen(input)
2
1 2
3 4
and i run this program i get this in return
2 //Dimension for matrix
1 //Iteration one begins
2
Printing current Row [1 2]
Printing curent Array [[1 2]]
3 //Iteration two begins
4
Printing current Row [3 4]
Printing curent Array [[3 4] [3 4]]
Final Array [[3 4] [3 4]]
I am not getting reason that why APPEND function is resulting in duplicating entries . There by want to know how to correct this also underlying CONCEPT