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

append array and change item #29077

Closed
mortezakhademan opened this issue Dec 3, 2018 · 1 comment

Comments

Projects
None yet
2 participants
@mortezakhademan
Copy link

commented Dec 3, 2018

go version go1.11.2 linux/amd64
go env Output
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/nvsh110/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/nvsh110/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build720309863=/tmp/go-build -gno-record-gcc-switches"

when i use append to array multiple and change one array item i see change two array!
var s []int
s1:=append(s,1)
s2:=append(s1,2)
s3:=append(s2,3)
s4:=append(s3,4)
s5:=append(s4,6)
s6:=append(s5,5)
s6[1]=8

fmt.Println(s1,s2,s3,s4,s5,s6)

output is:
[1] [1 2] [1 2 3] [1 2 3 4] [1 8 3 4 6] [1 8 3 4 6 5]

i change s6 but change s6 and s5!

@dominikh

This comment has been minimized.

Copy link
Member

commented Dec 3, 2018

This is working as intended.

Unlike many projects on GitHub, the Go project does not use its bug tracker for general discussion or asking questions. We only use our bug tracker for tracking bugs and tracking proposals going through the Proposal Process.

Please see https://golang.org/wiki/Questions for good places to ask questions.

@dominikh dominikh closed this Dec 3, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.