Insist that the castle peak does not relax, standing roots in the broken rock

In life, everyone always has a period of unyielding time. Some may be due to their studies, some may be due to money, and some may be due to their new lover. No matter what the initial motivation is, once they decide to do something, most of them will devote themselves wholeheartedly to it. However, adhering to this matter is like climbing a mountain, the higher the mountain, the fewer people stick to it, and finally can climb the top of the mountain to enjoy the beauty of the total is still a small number of people. From the very first day of pangu, the world was destined to win only a few people, and the majority of people were either attached to the strong or reduced to the bottom of the society. Whatever the fate of life, most people are still attached to the inevitable fate of others, and the only chance to change their own destiny, not disappear in the day-to-day laziness, is lost in the subway, with the passage of time is not in front of the wheel of time min is disappear in the years immersed for all. Life is like this, programming language learning is also like this, simple programming knowledge look not up, have to work hard all day to think about some fancy knowledge points to show off skills, as everyone knows, insist that castle peak does not relax, rooted in the broken rock. Without a solid foundation, the programming edifice, with its whistling programming skills alone, is bound to be vulnerable to the storm.


Arrays and slices

Array definition: An array is a sequence of numbered, fixed-length data lines of the same unique type, which can be any primitive type such as integer, string, or other defined type.

Slice definition: A slice is a reference to a contiguous fragment of an array, so a slice is a reference type (essentially, a slice can be thought of as an array of variable length).

1, the array

Var identifier [len]type var arr[10] string var arr[10]int... Var arrAge = [5]int{18, 20, 15, 22, 16} var arrLazy = [...] int{5, 6, 7, 8, 22} var arrKeyValue = [5]string{3: "Chris", 4: Func main() {var arr1 [5]int for I :=0; i < len(arr1); i++ { fmt.Printf("Array at index %d is %d\n", i, arr1[i]) } } func main() { a := [...] String {" a ", "b", "c", "d"} for I, v: the range of = a {FMT. Println (I, v)}} / / multi-dimensional array var [10]... [10]Copy the code

2, slicing

Var identifier []type // Create a slice, where type is the type of slice, Slice := make([]type, len, cap) s := make([]int, 10) func main() {a := []string{"a", "D ", "c", "d"} for I: = 0; i < len(a); i++ { fmt.Println(i) } } func main() { a := []string{"a", "b", "c", "d"} for i, v := range a { fmt.Println(i, V)}} / / slice restructuring s: = make (int [], 0, 10) / / slice interception s: = s [start: end] / / copy and additional s1_from: = int [] {1, 2, 3} s1_to: = make (int [], Sl3 := []int{1, 2, 3} sl3 = append(sl3, 4, 5, 6) sl3 := copy(s1_to, s1_from) sl3 := []int{1, 2, 3} sl3 = append(sl3, 4, 5)Copy the code

summary

A single spark can start a prairie fire, though about the content of the array part and sliced the summary of the relatively simple, but the total for both still relatively important knowledge points, especially with the section on the mastery of knowledge points, follow-up function of learning, or channel related content usually involves the use of slice, If time permits, it is highly recommended to spend more time on slicing. The importance of arrays is relatively lower than that of slicing. However, since it is learning a new programming language, or suggest that both are possible to master clearly, understand the use of the relevant knowledge points, do not fall into the “book to use less hate” situation.