提交 47801e4a 编写于 作者: V vitkarpov

Make some rewordings

上级 b0493cdb
......@@ -244,7 +244,7 @@ The reason that Go is concise because it has some default behaviors.
### array
`array` is array obviously, we define them as follows.
`array` is an array obviously, we define a one as follows.
var arr [n]type
......@@ -370,7 +370,7 @@ Attention: `append` will change the array that `slice` points to, and affect oth
### map
`map` is behaves like a dictionary in Python. Use the form `map[keyType]valueType` to define it.
`map` behaves like a dictionary in Python. Use the form `map[keyType]valueType` to define it.
Let's see some code. The 'set' and 'get' values in `map` are similar to `slice`, however the index in `slice` can only be of type 'int' while `map` can use much more than that: for example `int`, `string`, or whatever you want. Also, they are all able to use `==` and `!=` to compare values.
......
......@@ -151,23 +151,23 @@ In the fifth line, we put many values in one `case`, and we don't need to add th
integer := 6
switch integer {
case 4:
fmt.Println("integer <= 4")
fallthrough
case 5:
fmt.Println("integer <= 5")
fallthrough
case 6:
fmt.Println("integer <= 6")
fallthrough
case 7:
fmt.Println("integer <= 7")
fallthrough
case 8:
fmt.Println("integer <= 8")
fallthrough
default:
fmt.Println("default case")
case 4:
fmt.Println("integer <= 4")
fallthrough
case 5:
fmt.Println("integer <= 5")
fallthrough
case 6:
fmt.Println("integer <= 6")
fallthrough
case 7:
fmt.Println("integer <= 7")
fallthrough
case 8:
fmt.Println("integer <= 8")
fallthrough
default:
fmt.Println("default case")
}
This program prints the following information.
......@@ -295,13 +295,13 @@ Let's see one example in order to prove what i'm saying.
fmt.Println("x = ", x) // should print "x = 3"
}
Did you see that? Even though we called `add1`, and `add1` adds one to `a`, the value of `x` doesn't change.
Can you see that? Even though we called `add1` with `x`, the origin value of `x` doesn't change.
The reason is very simple: when we called `add1`, we gave a copy of `x` to it, not the `x` itself.
Now you may ask how I can pass the real `x` to the function.
We need use pointers here. We know variables are stored in memory and that they all have memory addresses. So, if we want to change the value of a variable, we must change the value at that variable's memory address. Therefore the function `add1` has to know the memory address of `x` in order to change its value. Here we pass `&x` to the function, and change the argument's type to the pointer type `*int`. Be aware that we pass a copy of the pointer, not copy of value.
We need use pointers here. We know variables are stored in memory and they have some memory addresses. So, if we want to change the value of a variable, we must change its memory address. Therefore the function `add1` has to know the memory address of `x` in order to change its value. Here we pass `&x` to the function, and change the argument's type to the pointer type `*int`. Be aware that we pass a copy of the pointer, not copy of value.
package main
import "fmt"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册