Function semantics

Slice parameters and mutation

A copied slice can share elements with the caller. Reslicing or appending changes the local slice value, not the caller length; append may allocate a different backing array. Return the new slice if the caller needs its updated length. Example output: '[7] 1'.

Formal Syntax & Structure

go syntaxgo
func update(s []T)

Working Example

Example Snippetgo
package main
import "fmt"
func update(s []int) { s[0] = 7; s = append(s, 9) }func main() {  s := make([]int, 1, 2)  s[0] = 3  update(s)  fmt.Println(s, len(s))}
Go Reference