### Go语言学习查缺补漏ing Day2

#### 一、函数返回参数命名的一个注意事项

func fun(x, y int) (s int, error) {
return x * y, nil
}

#### 二、new()和make()有什么不同？

// The new built-in function allocates memory. The first argument is a type,
// not a value, and the value returned is a pointer to a newly
// allocated zero value of that type.
func new(Type) *Type

// The make built-in function allocates and initializes an object of type
// slice, map, or chan (only). Like new, the first argument is a type, not a
// value. Unlike new, make's return type is the same as the type of its
// argument, not a pointer to it. The specification of the result depends on
// the type:
//  Slice: The size specifies the length. The capacity of the slice is
//  equal to its length. A second integer argument may be provided to
//  specify a different capacity; it must be no smaller than the
//  length. For example, make([]int, 0, 10) allocates an underlying array
//  of size 10 and returns a slice of length 0 and capacity 10 that is
//  backed by this underlying array.
//  Map: An empty map is allocated with enough space to hold the
//  specified number of elements. The size may be omitted, in which case
//  a small starting size is allocated.
//  Channel: The channel's buffer is initialized with the specified
//  buffer capacity. If zero, or the size is omitted, the channel is
//  unbuffered.
func make(t Type, size ...IntegerType) Type

import "fmt"

func main() {
l := new([]int)
l = append(l, 0)
fmt.Println(l)
}


#### 三、切片追加切片问题

package main

import "fmt"

func main() {
slice := []int{8, 8, 8}
append_slice := []int{2, 8}
slice = append(slice, append_slice)
fmt.Println(slice)
}


#### 四、简短模式声明变量的限制

package main

import "fmt"

var(
two = 200
)
one := 100

func main() {
fmt.Println(one,two)
}

1. 必须使用显示初始化，也就是手工给予初值。
2. 不能指定数据类型，编译器会根据你指定的初值自动推理变量的类型。
3. 只能在函数内部使用简短模式来声明变量。