Home >Backend Development >Golang >How Do I Get and Store the Address of a Go Struct Variable?
Obtaining and Storing the Address of a Struct Variable in Go
In Go, a struct variable's address can be obtained using the '&' operator. However, the default printing format in fmt.Println() treats struct addresses specially and prints them using '&{}' syntax.
To print the address of a struct variable explicitly, use the following code:
fmt.Printf("%p\n", &r)
This will output the memory address of the struct variable 'r'.
To store the address of a struct variable in a separate variable, use the following code:
addr := &r
The 'addr' variable will now contain the address of the struct variable 'r'.
The above is the detailed content of How Do I Get and Store the Address of a Go Struct Variable?. For more information, please follow other related articles on the PHP Chinese website!