Golang ProgramsGolang Programs

Copy an array by value and reference into another array

The values "Japan", "Australia", "Germany" are assigned to strArray1. strArray1 is then assigned to strArray2, which means that a copy of those values is created. The reassignment of the strArray1 to strArray3 from a value assignment to a reference assignment.
package main

import "fmt"

func main() {

	strArray1 := [3]string{"Japan", "Australia", "Germany"}
	fmt.Printf("strArray1: %v\n", strArray1)
	strArray2 := strArray1 // data is passed by value (copied)
	fmt.Printf("strArray2: %v\n", strArray2)
	strArray1[0] = "Canada"
	fmt.Printf("strArray1: %v\n", strArray1)
	fmt.Printf("strArray2: %v\n", strArray2)

	strArray3 := &strArray1
	fmt.Printf("strArray3: %v\n", strArray3)
	fmt.Printf("&strArray3: %v\n", &strArray3)
	fmt.Printf("*strArray3: %v\n", *strArray3)
	
}
Copy an array by value and reference into another array