To create a pointer variable of the string
type in Go, you can use the *
operator to declare a variable of type *string
. Here's how you can assign the string value "my string" to the variable at the address held by the pointer and print the value:
main.go311 chars15 lines
Output:
main.go10 chars2 lines
In the above example, we first declare a pointer variable pointerToStr
of type *string
. We then create a string variable str
with the value "my string", and assign the address of str
to pointerToStr
using the &
operator. Finally, we print the value referenced by pointerToStr
using the *
operator.
gistlibby LogSnag