Created
February 7, 2018 15:48
-
-
Save tomtsang/bfa69b8b9feb1c7ffa252d2a71ae9153 to your computer and use it in GitHub Desktop.
slice-1.go
This file contains hidden or 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() { | |
| s1 := []byte{'p', 'o', 'e', 'm'} //且 | |
| s2 := s1[2:] | |
| // s2[1] = 't' // 这个时候, s1, s2 都会改变 | |
| for i := 0; i < len(s1); i++ { | |
| fmt.Printf("Slice at %d is %v\n", i, s1[i]) | |
| } | |
| for i := 0; i < len(s2); i++ { | |
| fmt.Printf("Slice at %d is %v\n", i, s2[i]) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment