-1

I got this error "Cannot take the address of the result of append" when I try to :

s := []int{1, 2}
temp := &s
temp = &append(*temp, 3)

but if I make minor change like this:

s := []int{1, 2}
temp := &s
temp2 := append(*temp, 3)
temp = &temp2

there is no error.

I was navigated to this issue, but I can't understand it's comments.

Can anyone explain the differences?

June Wenston
  • 124
  • 10

1 Answers1

-2

In the second example you take the reference to the copy of the append function thats why you do not get a compiler error but it should not wor either. In the first example you try to get the reference directly to the append function thats why you get a compiler error

just a guy
  • 137
  • 7
  • thanks buddy, how can I directly dereference the returned value without help of a middle variable like 2nd example – June Wenston Nov 18 '20 at 09:22
  • 1
    I think that you do not need the reference of the append function but just the value it returns but thats something you should look up in the g documentation – just a guy Nov 18 '20 at 09:24
  • 1
    *In the second example you take the reference to the copy of the append function* No. He's taking the address of `temp2` which is perfectly valid. – super Nov 18 '20 at 09:41