1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
| package main
import "fmt"
func main() { complexArray1 := [3][]string{ []string{"d", "e", "f"}, []string{"g", "h", "i"}, []string{"j", "k", "l"}, }
fmt.Printf("The array: %v\n", complexArray1) complexArray2 := modifyComplexArray(complexArray1) fmt.Printf("The modified array: %v\n", complexArray2) fmt.Printf("The original array: %v\n", complexArray1)
fmt.Println(" ------- ") simpleArrray1 := []string{"1", "2", "3"}
fmt.Printf("The array: %v\n", simpleArrray1) simpleArrray2 := modifySimpleArry(simpleArrray1) fmt.Printf("The modified array: %v\n", simpleArrray2) fmt.Printf("The original array: %v\n", simpleArrray1)
simpleArrray2[0] = "XXX" fmt.Printf("The modified array: %v\n", simpleArrray2) fmt.Printf("The original array: %v\n", simpleArrray1)
t1 := []string{"1", "2", "3"} t2 := t1 t1[0] = "XXX" fmt.Println(t1) fmt.Println(t2)
}
func modifyComplexArray(a [3][]string) [3][]string { a[0][1] = "XXXXX" return a }
func modifySimpleArry(a []string) []string { a[0] = "modifed" return a }
|