...

/

Copying and Appending Slices

Copying and Appending Slices

This lesson describes the method of copying a slice or appending a slice to provide flexibility.

Modifying slices

To increase the capacity of a slice one must create a new and larger slice and copy the contents of the original slice into it.

Use of the copy function

Its syntax is as:

func copy(dst, src []T) int

The function copy copies slice elements of type T from a source src to a destination dst, overwriting the corresponding elements in dst, and it returns the number of elements ...