First, what you're using there is a slice, not an array. The array is
the data structure behind the slice.
When you call make([]int, 1, 10)
- an array of 10 ints is allocated
- a slice of length 1 and capacity 10 is created. It can be thought
of as a "smart pointer" to the array.
To do what you need, you want to 're-slice'. Modifying your example:
func main() {
s := make ([]int, 1, 10)
s[0] = 1
fmt.Printf("slice = %v\n", s)
s = s[0:2] // this resizes the slice to a length of 2
s[1] = 2
fmt.Printf("slice = %v\n", s)
}
Hope this helps,
Andrew