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
问题描述 slice原理一节的2.2示例的运行结果和解释错误。
如何找到这个错误
您认为应该如何? false
图片 如果有可能,尽量提供图片。
其他补充信息
示例的源代码:
package main
import ( "fmt" )
func AddElement(slice []int, e int) []int { return append(slice, e) }
func main() { var slice []int slice = append(slice, 1, 2, 3)
newSlice := AddElement(slice, 4) fmt.Println(&slice[0] == &newSlice[0])
}
错误原因: 因为AddElement函数内部append重新扩容了,但是它和原来的slice是两个内存地址值。
注:我的golang 1.16.7版本
The text was updated successfully, but these errors were encountered:
这个错误。请运行核查。
Sorry, something went wrong.
题目二? 是这个吗?
下面函数输出什么? ```go func SliceRise(s []int) { s = append(s, 0) for i := range s { s[i]++ } } func SlicePrint() { s1 := []int{1, 2} s2 := s1 s2 = append(s2, 3) SliceRise(s1) SliceRise(s2) fmt.Println(s1, s2) }
单选:
PS: 不知道你看的是第几次印刷的版本,有点对照不上。
感谢描述的是这个问题 #88
RainbowMango
No branches or pull requests
问题描述
slice原理一节的2.2示例的运行结果和解释错误。
如何找到这个错误
您认为应该如何?
false
图片
如果有可能,尽量提供图片。
其他补充信息
示例的源代码:
package main
import (
"fmt"
)
func AddElement(slice []int, e int) []int {
return append(slice, e)
}
func main() {
var slice []int
slice = append(slice, 1, 2, 3)
}
错误原因:
因为AddElement函数内部append重新扩容了,但是它和原来的slice是两个内存地址值。
注:我的golang 1.16.7版本
The text was updated successfully, but these errors were encountered: