-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
container/list: the last Element is changed when use array append #31404
Comments
That's because the
when |
@hengwu0 |
because slice‘s default capacity is 1, 2, 4, 8... |
Sorry,i can not understand capaccity will affect the tmp`s change |
For usage questions, see the venues in https://golang.org/wiki/Questions. It's not obvious that anything in Please note that code snippets filed to the issue tracker should generally be links to runnable, properly-formatted examples on https://play.golang.org. |
This doesn't have anything to do with container/list. It is just how slices and append work. See https://blog.golang.org/slices. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
YES
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
my code
Output is :
Output
What did you expect to see?
i expect to get
Begin : &{0xc0420661e0 0xc042066840 0xc0420661e0 [4 3 2 1]}
End : &{0xc0420661e0 0xc042066840 0xc0420661e0 [4 3 2 1]}
What did you see instead?
why i get
Begin : &{0xc0420661e0 0xc042066840 0xc0420661e0 [4 3 2 1]}
End : &{0xc0420661e0 0xc042066840 0xc0420661e0 [4 3 2 5]}
when i use append,the last element has changed.
The text was updated successfully, but these errors were encountered: