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
Subtract N number of Year, Month, Day, Hour, Minute, Second, Millisecond, Microsecond and Nanosecond to current date-time.
Convert Float32 to Float64 and Float64 to Float32
How to collect information about garbage collection?
Example: Split, Join, and Equal from BYTES Package
Replace numbers by zero from string
How to use wildcard or a variable in our URL for complex routing?
Regular expression to extract DNS host-name or IP Address from string
Various examples of Carbon date-time package in Golang
Sample program to create csv and write data
Get Set and Clear Session in Golang