Pointers
This commit is contained in:
parent
51ef8d631e
commit
27cf79ba61
1 changed files with 25 additions and 0 deletions
25
2moretypes/pointer.go
Normal file
25
2moretypes/pointer.go
Normal file
|
@ -0,0 +1,25 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func main() {
|
||||
fmt.Println("pointers stores memory address of a value")
|
||||
fmt.Println("zero value of pointers are nil")
|
||||
fmt.Println("The & operand return memory of a value")
|
||||
i := 42
|
||||
p := &i
|
||||
|
||||
fmt.Printf("%T, %v \n", *p, *p)
|
||||
fmt.Printf("%T, %v \n\n", p, p)
|
||||
fmt.Print(p)
|
||||
fmt.Printf("\n")
|
||||
fmt.Print(*p)
|
||||
fmt.Printf("\n")
|
||||
|
||||
*p = 21
|
||||
fmt.Println(i)
|
||||
|
||||
fmt.Println("Unlike C, Go has no pointer arithmetic !!!")
|
||||
}
|
Loading…
Reference in a new issue