I am playing with Go and facing the following question:
package main
import "fmt"
func main() {
var arr [2]*string
var s1 string = "hello"
arr[0] = &s1
arr[1] = &"world" // can't compile
fmt.Println(arr[0], arr[1])
fmt.Println(arr)
}
After compiling the above code I got the next error:
prog.go:10: cannot take the address of "world"
What is the reason I cannot obtain the address of the string literal? And if it is possible how can I do that?
Note: I obtained the address of s1
. Should I always introduce variables for literals to get back their addresses?