Answer the question
In order to leave comments, you need to log in
How to create a slice from an array without passing it by reference?
arr := [5]float64{1,2,3,4,5}
x := arr[0:5]
arr[2] = 10
x := arr[0:5]
Answer the question
In order to leave comments, you need to log in
package main
import (
"fmt"
)
func main() {
arr := [5]float64{1, 2, 3, 4, 5}
i := 3
x := append([]float64{}, arr[:i]...)
x[2] = 42
fmt.Println(x)
fmt.Println(arr)
}
arr := [5]float64{1,2,3,4,5}
var newslice = make([]float64, 5)
copy(newslice, arr[0:5])
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question