26-pointers/questions/README.md
2: Although a pointer can be put into a variable, it's not solely a variable. You're almost there! But this distinction is very important.
3: A pointer is just another value that can contain a memory address of a value.
type computer struct {
brand string
}
*computer{}var c computervar *c computervar c *computer CORRECT4: * in front of a type denotes a pointer type.
type computer struct {
brand string
}
c := &computer{"Apple"}
*c CORRECT&cc*computer1: * in front of a pointer value gets the value that is pointed by the pointer.
2: & in front of a value gets the memory address of that value
4: * in front of a type denotes a pointer type.
type computer struct {
brand string
}
var a, b *computer
fmt.Print(a == b)
a = &computer{"Apple"}
b = &computer{"Apple"}
fmt.Print(" ", a == b, " ", *a == *b)
3: a and b are nil at the beginning, so they are equal. However, after that, they get two different memory addresses from the composite literals, so their addresses are not equal but their values (that are pointed by the pointers) are equal.
type computer struct {
brand string
}
func main() {
a = &computer{"Apple"}
b := a
change(b)
change(b)
}
func change(c *computer) {
c.brand = "Indie"
c = nil
}
4: Every time a func runs, it creates new variables from its input params and named result values (if any). There two pointer variables: a and b. Then there are, two more pointer variables because: change is called two times.
2: Map elements are not addressable, so you cannot take their addresses.