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
Copy an array by value and reference into another array
How to append text to a file in Golang?
How to wait for Goroutines to Finish Execution?
Convert Int data type to Int16 Int32 Int64
Get Year, Month, Day, Hour, Min and Second from a specified date
Split a character string based on change of character
How to check UPPERCASE characters in a string in Golang?
Functions mess (recursive anonymous function) in Golang
Example: ReadAll, ReadDir, and ReadFile from IO Package
Sierpinski Carpet in Go Programming Language