Slices with Functions

This lesson explains handling slices as parameters to the functions in detail.

Passing a slice to a function #

If you have a function that must operate on an array, you probably always want to declare the formal parameter to be a slice. When you call the function, slice the array to create (efficiently) a slice reference and pass that. For example, here is a program that sums all elements in an array:

Get hands-on with 1400+ tech skills courses.