Standard library / reflect

reflect.Copy()

Copies up to the smaller length of source and destination; overlapping slices are supported. Expected stdout: '3 [1 1 2 3]\n'.

Formal Syntax & Structure

go syntaxgo
func Copy(dst, src Value) int

Parameters & Attributes

NameTypeDescription
dstValueDestination array or slice.
srcValueSource array, slice or compatible string.

Return Value

int

Copies up to the smaller length of source and destination; overlapping slices are supported.

Working Example

Example Snippetgo
package main
import (  "fmt"  "reflect")
func main() {  a := []int{1, 2, 3, 4}  n := reflect.Copy(reflect.ValueOf(a[1:]), reflect.ValueOf(a[:3]))  fmt.Println(n, a)}
Go Reference