Skip to content

书1 图13-5配图中“切片2”画法错误 #33

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
pbrong opened this issue Dec 4, 2022 · 1 comment
Closed

书1 图13-5配图中“切片2”画法错误 #33

pbrong opened this issue Dec 4, 2022 · 1 comment

Comments

@pbrong
Copy link

pbrong commented Dec 4, 2022

切片2线条应该从第三项开始,且cap=8

@bigwhite
Copy link
Owner

bigwhite commented Jan 4, 2023

切片s2是基于切片s1进行的slicing,确认了一下,图中没错。下面是确认的代码:

package main

import "fmt"

func main() { 
    u := [10]byte{11, 12, 13, 14, 15, 16, 17, 18, 19, 20}
    s1 := u[1:5]
    s2 := s1[2:4]
    fmt.Println(s1, cap(s1)) // [12 13 14 15] 9
    fmt.Println(s2, cap(s2)) // [14 15] 7
}

@bigwhite bigwhite closed this as completed Jan 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants