Skip to content

Instantly share code, notes, and snippets.

@yakuter
Created February 14, 2024 11:05
Show Gist options
  • Save yakuter/b93569aa8060829a3ff44f27c9edeb7a to your computer and use it in GitHub Desktop.
Save yakuter/b93569aa8060829a3ff44f27c9edeb7a to your computer and use it in GitHub Desktop.
Copy and Movement 1
src := []int{1, 2, 3, 4, 5}
dst := make([]int, 5)
// copy from slice to slice
copied := copy(dst, src)
// copied: 5
// dst: [1 2 3 4 5]
// copy from string to slice
var b = make([]byte, 5)
copy(b, "Hello, world!")
// b == []byte("Hello")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment