From 27cf79ba6102f4c845dbee14265a3eaea0a8e075 Mon Sep 17 00:00:00 2001 From: asandikci Date: Mon, 10 Jul 2023 10:22:35 +0300 Subject: [PATCH] Pointers --- 2moretypes/pointer.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 2moretypes/pointer.go diff --git a/2moretypes/pointer.go b/2moretypes/pointer.go new file mode 100644 index 0000000..54f87e5 --- /dev/null +++ b/2moretypes/pointer.go @@ -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 !!!") +}