How to declare and access pointer variable?
Example
package main
import "fmt"
func main() {
var actualVar string = "Australia" /* variable declaration */
var pointerVar *string /* pointer variable declaration */
/* store address of actual variable in pointer variable*/
pointerVar = &actualVar
fmt.Printf("\nAddress of variable: %v", &actualVar )
fmt.Printf("\nAddress stored in pointer variable: %v", pointerVar )
fmt.Printf("\nValue of Actual Variable: %s",actualVar )
fmt.Printf("\nValue of Pointer variable: %s",*pointerVar )
}
Output
Address of variable: 0x114f40e0
Address stored in pointer variable: 0x114f40e0
Value of Actual Variable: Australia
Value of Pointer variable: Australia
Most Helpful This Week
How to check if a string contains a white space in Golang?
Regular expression to extract date(YYYY-MM-DD) from string
How to get struct variable information using reflect package?
Various examples of printing and formatting in Golang
Encoding and Decoding using json.Marshal and json.Unmarshal
How do you write multi-line strings in Go?