summaryrefslogtreecommitdiffhomepage
path: root/go.html.markdown
diff options
context:
space:
mode:
authorPetr Houška <houskape@gmail.com>2020-02-08 22:57:43 +0100
committerGitHub <noreply@github.com>2020-02-08 22:57:43 +0100
commit3869472f749e74f554eda136654ec9d098cf0fb7 (patch)
tree37fd26d15de348ea989bea9c1672e260d014ba03 /go.html.markdown
parente021d05c2f02018bcd7d13c7b455c7db56faf386 (diff)
[go/en] Clarify safety of local variable address taking.
Diffstat (limited to 'go.html.markdown')
-rw-r--r--go.html.markdown3
1 files changed, 2 insertions, 1 deletions
diff --git a/go.html.markdown b/go.html.markdown
index 49f1ade4..ec812f20 100644
--- a/go.html.markdown
+++ b/go.html.markdown
@@ -168,10 +168,11 @@ func learnNamedReturns(x, y int) (z int) {
// Go is fully garbage collected. It has pointers but no pointer arithmetic.
// You can make a mistake with a nil pointer, but not by incrementing a pointer.
+// Unlike in C/Cpp taking and returning an address of a local varible is also safe.
func learnMemory() (p, q *int) {
// Named return values p and q have type pointer to int.
p = new(int) // Built-in function new allocates memory.
- // The allocated int is initialized to 0, p is no longer nil.
+ // The allocated int slice is initialized to 0, p is no longer nil.
s := make([]int, 20) // Allocate 20 ints as a single block of memory.
s[3] = 7 // Assign one of them.
r := -2 // Declare another local variable.