File tree Expand file tree Collapse file tree 3 files changed +41
-5
lines changed Expand file tree Collapse file tree 3 files changed +41
-5
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change
1
+ package main
2
+
3
+ import "fmt"
4
+
5
+ type Point struct {
6
+ x float64
7
+ y float64
8
+ }
9
+
10
+ func main () {
11
+ // Structs are value types.
12
+ p1 := Point {10 , 20 }
13
+ p2 := p1 // A copy of the struct `p1` is assigned to `p2`
14
+ fmt .Println ("p1 = " , p1 )
15
+ fmt .Println ("p2 = " , p2 )
16
+
17
+ p2 .x = 15
18
+ fmt .Println ("\n After modifying p2:" )
19
+ fmt .Println ("p1 = " , p1 )
20
+ fmt .Println ("p2 = " , p2 )
21
+ }
Original file line number Diff line number Diff line change
1
+ package main
2
+
3
+ import "fmt"
4
+
5
+ type Point struct {
6
+ x float64
7
+ y float64
8
+ }
9
+
10
+ func main () {
11
+ // Two structs are equal if all their corresponding fields are equal.
12
+ p1 := Point {3.4 , 5.2 }
13
+ p2 := Point {3.4 , 5.2 }
14
+
15
+ if p1 == p2 {
16
+ fmt .Println ("Point p1 and p2 are equal." )
17
+ } else {
18
+ fmt .Println ("Point p1 and p2 are not equal." )
19
+ }
20
+ }
You can’t perform that action at this time.
0 commit comments