Skip to content

Commit 70813db

Browse files
Fixed the output to be more clear
1 parent 245ac49 commit 70813db

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

topics/go/language/pointers/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ https://godoc.org/golang.org/x/tools/go/ssa
108108

109109
## Code Review
110110

111-
[Pass by Value](example1/example1.go) ([Go Playground](https://play.golang.org/p/kEy5gesvMo))
112-
[Sharing data I](example2/example2.go) ([Go Playground](https://play.golang.org/p/iJ5k0BFYXB))
111+
[Pass by Value](example1/example1.go) ([Go Playground](https://play.golang.org/p/xC4bDm3u-U))
112+
[Sharing data I](example2/example2.go) ([Go Playground](https://play.golang.org/p/g0Cs0FVpyi))
113113
[Sharing data II](example3/example3.go) ([Go Playground](https://play.golang.org/p/KRKrUCcTYe))
114114
[Stack vs Heap](example4/example4.go) ([Go Playground](https://play.golang.org/p/jYkpV-zQ_o))
115115
[Stack grow](example5/example5.go) ([Go Playground](https://play.golang.org/p/tpDOwBCvqW))

topics/go/language/pointers/example1/example1.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,20 @@ func main() {
1010
count := 10
1111

1212
// Display the "value of" and "address of" count.
13-
println("Before:", count, &count)
13+
println("count:\tValue Of[",count, "]\tAddr Of[", &count, "]")
1414

15-
// Pass the "value of" the variable count.
15+
// Pass the "address of" the variable count.
1616
increment(count)
1717

18-
println("After: ", count, &count)
18+
println("count:\tValue Of[",count, "]\tAddr Of[", &count, "]")
1919
}
2020

21-
// increment declares count as a variable whose value is
22-
// always an integer.
21+
// increment declares count as a pointer variable whose value is
22+
// always an address and points to values of type int.
2323
//go:noinline
2424
func increment(inc int) {
2525

26-
// Increment the "value of" inc.
26+
// Increment the value that the "pointer points to". (de-referencing)
2727
inc++
28-
println("Inc: ", inc, &inc)
29-
}
28+
println("inc:\tValue Of[",inc, "]\tAddr Of[", &inc, "]")
29+
}

topics/go/language/pointers/example2/example2.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ func main() {
1111
count := 10
1212

1313
// Display the "value of" and "address of" count.
14-
println("Before:", count, &count)
14+
println("count:\tValue Of[",count, "]\t\tAddr Of[", &count, "]")
1515

1616
// Pass the "address of" the variable count.
1717
increment(&count)
1818

19-
println("After: ", count, &count)
19+
println("count:\tValue Of[",count, "]\t\tAddr Of[", &count, "]")
2020
}
2121

2222
// increment declares count as a pointer variable whose value is
@@ -26,5 +26,5 @@ func increment(inc *int) {
2626

2727
// Increment the value that the "pointer points to". (de-referencing)
2828
*inc++
29-
println("Inc: ", *inc, &inc, inc)
30-
}
29+
println("inc:\tValue Of[",inc, "]\tAddr Of[", &inc, "]\tValue Points To[", *inc, "]")
30+
}

0 commit comments

Comments
 (0)