Created
January 31, 2016 07:56
-
-
Save hackintoshrao/cd761618997626006434 to your computer and use it in GitHub Desktop.
Adding elements onto the slice beyonf the size of the underlying array its pointing to
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() { | |
array := [4]int{1,2,3,4} | |
sliceFromArray := array[:3] | |
fmt.Printf("array = %v , slice = %v\n",array,sliceFromArray) | |
sliceFromArray[2] = 4 | |
fmt.Printf("array = %v , slice = %v\n",array,sliceFromArray) | |
sliceFromArray = append(sliceFromArray,5) | |
fmt.Printf("array = %v , slice = %v\n",array,sliceFromArray) | |
sliceFromArray = append(sliceFromArray,6) | |
fmt.Printf("array = %v , slice = %v\n",array,sliceFromArray) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment