Copy an Array by Value and Reference into Another Array in Golang Last Updated : 08 Jun, 2020 Comments Improve Suggest changes Like Article Like Report Array in Golang is a numbered sequence of elements of the same type. The size of the array is fixed. We can access the elements by their index. You can declare an array of size n and type T specifying this way mentioned below. var array[n]T Go doesn't have an inbuilt function to copy an array to another array. There are two ways of copying an array to another array: By Value By Reference 1. Copying By Value: If we copy an array by value and later changes are made in values of original array, the same changes won't be reflected in the copy of the original array. 2. Copying By Reference: If we copy an array by reference and later make any changes in the original array, then they will reflect in the copy of the original array created. Example: C // Golang program to copy an array by value // and reference into another array package main import "fmt" func main() { // original string strArray := [3]string{"Apple", "Mango", "Guava"} // data is passed by value Arraybyval := strArray // data is passed by reference Arraybyref := &strArray fmt.Printf("strArray: %v\n", strArray) fmt.Printf("Arraybyval : %v\n", Arraybyval) fmt.Printf("*Arraybyref : %v\n", *Arraybyref) strArray[0] = "Watermelon" fmt.Printf("After making changes") fmt.Printf("strArray: %v\n", strArray) fmt.Printf("Arraybyval: %v\n", Arraybyval) fmt.Printf("*Arraybyref: %v\n", *Arraybyref) } Output: strArray: [Apple Mango Guava] Arraybyval : [Apple Mango Guava] *Arraybyref : [Apple Mango Guava] After making changesstrArray: [Watermelon Mango Guava] Arraybyval: [Apple Mango Guava] *Arraybyref: [Watermelon Mango Guava] Comment More infoAdvertise with us Next Article Copy an Array by Value and Reference into Another Array in Golang D devanshigupta1304 Follow Improve Article Tags : Go Language Golang-Arrays Similar Reads How to Copy an Array into Another Array in Golang? In Go, an array is a fixed-length sequence that holds elements of a specific type. Unlike slices, arrays have a constant size, which is determined when the array is declared. Copying one array to another is straightforward but requires that both arrays have the same length and type.Examplepackage ma 3 min read How to copy one slice into another slice in Golang? In Go, a Slice is a variable-length sequence that can hold elements of the same type. You canât mix different types of elements in a single slice. To copy one slice into another, Go provides a built-in function called copy(). This function allows you to duplicate the elements from one slice (the sou 3 min read How to Copy Struct Type Using Value and Pointer Reference in Golang? A structure or struct in Golang is a user-defined data type that allows to combine data types of different kinds and act as a record. A struct variable in Golang can be copied to another variable easily using the assignment statement(=). Any changes made to the second struct will not be reflected ba 2 min read Golang Pointer to an Array as Function Argument Prerequisite: Pointers in Golang Pointers in Go programming language or Golang is a variable which is used to store the memory address of another variable. Whereas an array is a fixed-length sequence which is used to store homogeneous elements in the memory. You can use the pointers to an array and 3 min read How to Copy Array by Value in JavaScript ? There are various methods to copy array by value in JavaScript.1. Using Spread OperatorThe JavaScript spread operator is a concise and easy metho to copy an array by value. The spread operator allows you to expand an array into individual elements, which can then be used to create a new array.Syntax 4 min read Like