Original post

I am bit confused about how memory allocation works while appending to a slice. I have this sample program:

package main

import "fmt"

func main() {
	var a []int
	a = append(a, 3)
	fmt.Println(&a[0])
	a = append(a, 5)
	fmt.Println(&a[0])
}

I see the output as:

0xc0000b6018
0xc0000b6030

I am confused about why the address of a[0] is different in both the cases. I would be very thankful for an explanation of this observation.