Junior — Senior
What will the program print when passing a slice to a function
livecode
Task condition
Determine the output of the following Go program. In the modify function, the passed slice is iterated over and all its elements are replaced with the value 5. Then, the slice is printed to the screen. In main, the original slice src is created, passed to modify, and then printed again.
package main
import (
"fmt"
)
func modify(arr []int) {
// arr = append(arr, 125)
for i := range arr {
arr[i] = 5
}
fmt.Println(arr)
}
func main() {
src := []int{1, 2, 3, 4}
modify(src)
fmt.Println(src)
}
What will be the result of the program execution?