A pointer
is used to hold the address of a variable.
Syntax
var
pointerName *dataType
Example
var intPtr
*int
var a int
= 10
intPtr =
&a
'intPtr'
can able to hold the address of an integer variable. The & operator gives
the address of a variable.
App.go
package main import "fmt" func main() { var intPtr *int var a int = 10 intPtr = &a fmt.Println("Value of a is : ", a) fmt.Println("\na is stored at address : ", intPtr) fmt.Println("Value of a is : ", *intPtr) }
Output
Value of a
is : 10
a is
stored at address : 0xc000014058
Value of a
is : 10
No comments:
Post a Comment