在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
1 package main 2 3 import "fmt" 4 //import OS "os" 5 //import "strings" 6 //import "path/filepath" 7 8 type Stack []interface{} 9 10 func (s *Stack)f() { 11 stack := *s 12 13 fmt.Printf("%p %d %d\n", &s, len(stack), cap(stack)) 14 15 *s = stack[:len(stack) - 1] //减少 16 17 fmt.Printf("%p %d %d\n", &s, len(*s), cap(*s)) 18 19 fmt.Printf("%p %d %d\n", stack, len(stack), cap(stack)) 20 21 stack = append(stack, "e", "f") //增加 22 23 fmt.Printf("%p %d %d\n",stack, len(stack), cap(stack)) 24 } 25 26 27 func main() { 28 var s Stack 29 s = append(s, "a", "b", "c", "d") 30 s.f() 31 fmt.Println(s) 32 fmt.Printf("%t\n", false) 33 }
|
请发表评论