Skip to content
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

Slices question #10

Closed
rusinikita opened this issue Mar 27, 2024 · 0 comments
Closed

Slices question #10

rusinikita opened this issue Mar 27, 2024 · 0 comments
Labels
good first issue Good for newcomers help wanted Extra attention is needed

Comments

@rusinikita
Copy link
Owner

rusinikita commented Mar 27, 2024

Understanding slices work

func main() {
	var x []int
	x = append(x, 0) // explanation 1: new array created with capacity 2
	x = append(x, 1) // explanation 2: same array index 1 set to 1
	x = append(x, 2) // explanation 3: new array created with len 4, 012 setted

        // expected: [0 1 2 3 0 1 2 4]
        // wtf: [0 1 2 4 0 1 2 4]
	fmt.Println(append(append(x, 3), append(x, 4)...))
        // explanation 4: no new arrays created, index 3 set to 3, and then to 4
}
@rusinikita rusinikita added help wanted Extra attention is needed good first issue Good for newcomers labels Mar 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant