Skip to content

Commit eb50c61

Browse files
committed
adding pointers for golang
1 parent b635e1d commit eb50c61

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

pointers.go

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Pointer is just the reference to the memory address since you're directly passing on to that address it makes a 100% guarantee that actual value is passed on.
2+
package main
3+
4+
import (
5+
"fmt"
6+
)
7+
8+
func main() {
9+
// var ptr *int
10+
// fmt.Println("The actual number of pointer is: ", ptr)
11+
12+
myNumber := 35
13+
// For reference to the memory address we use "&" this
14+
var ptr = &myNumber
15+
fmt.Println("For printing the actual value of pointer here is: ", ptr)
16+
fmt.Println("For printing the actual value of pointer here is: ", *ptr)
17+
*ptr = *ptr + 2
18+
fmt.Println("The new value is: ", myNumber)
19+
20+
}

0 commit comments

Comments
 (0)