![Learn Data Structures and Algorithms with Golang](https://wfqqreader-1252317822.image.myqcloud.com/cover/744/36698744/b_36698744.jpg)
上QQ阅读APP看书,第一时间看更新
Slice function
Slices are passed by referring to functions. Big slices can be passed to functions without impacting performance. Passing a slice as a reference to a function is demonstrated in the code as follows (slices.go):
//twiceValue method given slice of int type
func twiceValue(slice []int) {
var i int
var value int
for i, value = range slice {
slice[i] = 2*value
}
}
// main method
func main() {
var slice = []int{1,3,5,6}
twiceValue(slice)
var i int
for i=0; i< len(slice); i++ {
fmt.Println(“new slice value”, slice[i])
}
}
Run the following command:
go run slices.go
The following screenshot displays the output:
![](https://epubservercos.yuewen.com/AA6936/19470380301498306/epubprivate/OEBPS/Images/2e58fe8f-0186-4866-9e9d-b0e255611dae.png?sign=1738872944-Ck5Oq4sB11tsa30HvbdM21D3uas7Fi2D-0-ca38b0ace32ea7d7a7f7e82fd20bab53)
Now that we know what slices are, let's move on to two-dimensional slices in the next section.