SnIPPETsX › func change(s *[]int)
func change(s *[]int)
Go · updated Oct 14, 2026 · 16 lines
file-3.go
package main
import "fmt"
func change(s *[]int) {
*s = append(*s, 4)
fmt.Println("inside:", s) // 1,2,3,4
}
func main() {
a := []int{1, 2, 3}
change(&a)
fmt.Println("outside:", a) // 1,2,3,4
}
Run this Go snippet
Open this snippet on SnIPPETsX to run the Go code in your browser, edit it together with others in real time, or fork it into your own copy. No install or account is needed.