Created
January 26, 2019 01:51
-
-
Save krishnakumar4a4/bec8f71901146c798ebfaa3b560a76b7 to your computer and use it in GitHub Desktop.
Appending elements inside multidimensional arrays in golang using slices
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
) | |
func main() { | |
// Inner dimension cannot be extended if given length | |
v := [3][3][]int{} | |
// v[0][0][:] gives the slice of the existing elements | |
v[0][0] = append(v[0][0][:],1) | |
v[0][0] = append(v[0][0][:],1) | |
v[0][1] = append(v[0][1][:],2) | |
v[0][1] = append(v[0][1][:],3) | |
fmt.Println("v: ",v) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment