Application
Create new folder named src. In src folder, create new file named main.go as below:
package main
import "fmt"
func main() {
var a = [3]int{4, 1, -2}
ChangeValueWithArray(a)
fmt.Println("Change Value with Array")
fmt.Println("a: ", a)
fmt.Println("Change Value with Slice")
ChangeValueWithSlice(a[:])
fmt.Println("a: ", a)
}
func ChangeValueWithArray(a [3]int) {
a[1] = 999
}
func ChangeValueWithSlice(slice []int) {
slice[1] = 999
}
Output
Open Terminal windows in Visual Studio Code and run command line: go run main.go
Change Value with Array
a: [4 1 -2]
Change Value with Slice
a: [4 999 -2]