Fix additional typos and grammatical errors
This commit is contained in:
@@ -4,7 +4,7 @@ In this section, we are going to teach you how to define constants, variables wi
|
||||
|
||||
## Define variables
|
||||
|
||||
There are many forms of syntax that can use to define variables in Go.
|
||||
There are many forms of syntax that can be used to define variables in Go.
|
||||
|
||||
The keyword `var` is the basic form to define variables, notice that Go puts the variable type `after` the variable name.
|
||||
|
||||
@@ -29,7 +29,7 @@ Define multiple variables with initial values.
|
||||
*/
|
||||
var vname1, vname2, vname3 type = v1, v2, v3
|
||||
|
||||
Do you think it's too tedious to define variables use the way above? Don't worry because the Go team has found this to be aproblem. Therefore if you want to define variables with initial values, we can just omit the variable type, so the code will look like this instead:
|
||||
Do you think that it's too tedious to define variables use the way above? Don't worry, because the Go team has also found this to be a problem. Therefore if you want to define variables with initial values, we can just omit the variable type, so the code will look like this instead:
|
||||
|
||||
/*
|
||||
Define three variables with type "type", and initialize their values.
|
||||
@@ -51,7 +51,7 @@ Now it looks much better. Use `:=` to replace `var` and `type`, this is called a
|
||||
|
||||
_, b := 34, 35
|
||||
|
||||
If you don't use any variable that you defined in the program, the compiler will give you compile errors. Try to compile following code, and see what happens.
|
||||
If you don't use variables that you've defined in your program, the compiler will give you compilation errors. Try to compile the following code and see what happens.
|
||||
|
||||
package main
|
||||
|
||||
@@ -93,7 +93,7 @@ In Go, we use `bool` to define a variable as boolean type, the value can only be
|
||||
|
||||
### Numerical types
|
||||
|
||||
Integer types includ both signed and unsigned integer types. Go has `int` and `uint` at the same time, they have same length, but specific length depends on your operating system. They use 32-bit in 32-bit operating systems, and 64-bit in 64-bit operating systems. Go also has types that have specific length including `rune`, `int8`, `int16`, `int32`, `int64`, `byte`, `uint8`, `uint16`, `uint32`, `uint64`. Note that `rune` is alias of `int32` and `byte` is alias of `uint8`.
|
||||
Integer types include both signed and unsigned integer types. Go has `int` and `uint` at the same time, they have same length, but specific length depends on your operating system. They use 32-bit in 32-bit operating systems, and 64-bit in 64-bit operating systems. Go also has types that have specific length including `rune`, `int8`, `int16`, `int32`, `int64`, `byte`, `uint8`, `uint16`, `uint32`, `uint64`. Note that `rune` is alias of `int32` and `byte` is alias of `uint8`.
|
||||
|
||||
One important thing you should know that you cannot assign values between these types, this operation will cause compile errors.
|
||||
|
||||
@@ -107,7 +107,7 @@ Although int has a longer length than uint8, and has the same length as int32, y
|
||||
|
||||
Float types have the `float32` and `float64` types and no type called `float`. The latter one is the default type if using brief statement.
|
||||
|
||||
That's all? No! Go support complex numbers as well. `complex128` (with a 64-bit real and 64-bit imaginary part) is the default type, if you need a smaller type, there is one called `complex64` (with a 32-bit real and 32-bit imaginary part). Its form is `RE+IMi`, where `RE` is real part and `IM` is imaginary part, the last `i` is imaginary number. There is a example of complex number.
|
||||
That's all? No! Go supports complex numbers as well. `complex128` (with a 64-bit real and 64-bit imaginary part) is the default type, if you need a smaller type, there is one called `complex64` (with a 32-bit real and 32-bit imaginary part). Its form is `RE+IMi`, where `RE` is real part and `IM` is imaginary part, the last `i` is imaginary number. There is a example of complex number.
|
||||
|
||||
var c complex64 = 5+5i
|
||||
//output: (5+5i)
|
||||
@@ -256,7 +256,7 @@ in `[n]type`, `n` is the length of the array, `type` is the type of its elements
|
||||
fmt.Printf("The first element is %d\n", arr[0]) // get element value, it returns 42
|
||||
fmt.Printf("The last element is %d\n", arr[9]) //it returns default value of 10th element in this array, which is 0 in this case.
|
||||
|
||||
Because length is a part of the array type, `[3]int` and `[4]int` are different types, so we cannot change the length of arrays. When you use arrays as arguments, functions get their copies instead of references! If you want to use reference, you may want to use `slice`, which we'll talk about later.
|
||||
Because length is a part of the array type, `[3]int` and `[4]int` are different types, so we cannot change the length of arrays. When you use arrays as arguments, functions get their copies instead of references! If you want to use references, you may want to use `slice`. We'll talk about later.
|
||||
|
||||
It's possible to use `:=` when you define arrays.
|
||||
|
||||
@@ -264,7 +264,7 @@ It's possible to use `:=` when you define arrays.
|
||||
|
||||
b := [10]int{1, 2, 3} // define a int array with 10 elements, of which the first three are assigned. The rest of them use the default value 0.
|
||||
|
||||
c := [...]int{4, 5, 6} // use `…` to replace the length paramter and Go will calculate it for you.
|
||||
c := [...]int{4, 5, 6} // use `…` to replace the length parameter and Go will calculate it for you.
|
||||
|
||||
You may want to use arrays as arrays' elements. Let's see how to do this.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user