Created
February 14, 2024 11:05
-
-
Save yakuter/b93569aa8060829a3ff44f27c9edeb7a to your computer and use it in GitHub Desktop.
Copy and Movement 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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