Skip to content

Commit 83eee73

Browse files
committed
Ders 37
1 parent cc2f9fe commit 83eee73

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

37_pointers/main.go

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package main
2+
3+
import "fmt"
4+
5+
func main() {
6+
7+
//name := "arin"
8+
9+
/* fmt.Println(name)
10+
fmt.Println(&name) */ // & --> address operator
11+
12+
/* fmt.Println(x)
13+
fmt.Println(&x)
14+
15+
fmt.Println()
16+
17+
fmt.Printf("%T, %v\n", x, x)
18+
fmt.Printf("%T, %v\n", &x, &x) */
19+
20+
/* y := &x
21+
fmt.Printf("%T, %v\n", y, y)
22+
23+
z := &name
24+
fmt.Printf("%T, %v\n", z, z) */
25+
26+
/* x := 22 */
27+
/* fmt.Println(x) // 22
28+
fmt.Println(&x) // 22 nin adresi &x ---> *int
29+
fmt.Println(*(&x)) // dereferencing
30+
fmt.Println(&(*(&x))) // * --->> ilgili adresteki değeri gösteriri
31+
fmt.Println(*(&(*(&x))))
32+
33+
fmt.Println(3 * 5) */
34+
35+
/* x1 := 10
36+
x2 := x1
37+
fmt.Println(x1, x2)
38+
x1 = 5
39+
fmt.Println(x1, x2) */
40+
41+
/* x1 := 10
42+
x2 := &x1
43+
fmt.Println(x1, x2)
44+
fmt.Println(x1, *x2)
45+
46+
*x2 = 3
47+
48+
fmt.Println(x1, *x2)
49+
50+
x3 := &x1
51+
52+
*x3 = 5
53+
54+
fmt.Println(x1, *x2, *x3) */
55+
56+
// x1 := [4]int{1, 10, 100, 1000} // array pass by value
57+
58+
x1 := []int{1, 10, 100, 1000}
59+
x2 := x1
60+
61+
fmt.Println(x1, x2)
62+
63+
x2[0] = 3
64+
fmt.Println(x2)
65+
fmt.Println(x1) // slice pass by reference
66+
67+
}

0 commit comments

Comments
 (0)