Created
July 25, 2015 16:36
The value is assigned means that generate a copy.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
type Pool struct { | |
array [3]int | |
} | |
func main() { | |
a := [...]int{1, 2, 3} | |
pool := Pool{ | |
array: a, | |
} | |
fmt.Printf("Pool: %v\n", pool) | |
a[0] = 4 | |
fmt.Printf("Pool: %v\n", pool) | |
pool.array = a | |
fmt.Printf("Pool: %v\n", pool) | |
a[1] = 5 | |
fmt.Printf("Pool: %v\n", pool) | |
b := a | |
fmt.Printf("B: %v\n", b) | |
a[2] = 6 | |
fmt.Printf("B: %v\n", b) | |
b[2] = 7 | |
fmt.Printf("A: %v\n", a) | |
} | |
// Output: | |
// Pool: {[1 2 3]} | |
// Pool: {[1 2 3]} | |
// Pool: {[4 2 3]} | |
// Pool: {[4 2 3]} | |
// B: [4 5 3] | |
// B: [4 5 3] | |
// A: [4 5 6] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment