We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
copy函数实际上会返回一个int值,这个int是一个size,计算逻辑为 size = min(len(dst), len(src)) 这个size的大小,决定了src要copy几个元素给dst 由于题目中,dst声明了,但是没有进行初始化,所以dst的len是0 因此实际没有从src上copy到任何元素给dst
修改版本如下:
func main() { var src, dst []int src = []int{1, 2, 3} //这是未修改前的 copy(dst, src) fmt.Println(dst) //这是修改时添加的 dst = make([]int, len(src)) copy(dst, src) fmt.Println(dst) }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
输出结果为[]
copy函数实际上会返回一个int值,这个int是一个size,计算逻辑为
size = min(len(dst), len(src))
这个size的大小,决定了src要copy几个元素给dst
由于题目中,dst声明了,但是没有进行初始化,所以dst的len是0
因此实际没有从src上copy到任何元素给dst
修改版本如下:
The text was updated successfully, but these errors were encountered: