Skip to content

Instantly share code, notes, and snippets.

@tomtsang
Created February 7, 2018 15:48
Show Gist options
  • Select an option

  • Save tomtsang/bfa69b8b9feb1c7ffa252d2a71ae9153 to your computer and use it in GitHub Desktop.

Select an option

Save tomtsang/bfa69b8b9feb1c7ffa252d2a71ae9153 to your computer and use it in GitHub Desktop.
slice-1.go
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