To create a pointer to a bool in Go, you need to first create a bool variable and then create a pointer to that variable using the address-of operator '&'.
main.go172 chars12 lines
In the above code snippet, we first create a bool variable b
and initialize it to true
. We then create a pointer variable ptr
of type *bool
, and assign it the memory address of b
using the address-of operator '&'.
To access the value stored in the bool variable using the pointer, we use the dereference operator *
. In the fmt.Println(*ptr)
statement, we print the value of b
that is stored at the memory location pointed to by ptr
.
gistlibby LogSnag