/*
* @Author: mrtao
* @Date: 2018-08-14 14:48:25
* @Last Modified by: mrtao
* @Last Modified time: 2018-08-14 15:55:51
*/
package main
import "fmt"
func main() {
// 指针
var p *int
a := 10
p = &a
// p = new(int)
// *p = 10
fmt.Println(*p)
// 数组
var id [50]int
fmt.Println(len(id))
// for i := 0; i < len(id); i++ {
// fmt.Println(id[i])
// }
id2 := [3]int{1, 2, 3}
fmt.Println(id2)
// 切片
b := []int{1, 2, 3, 4, 5} //不定长数组
s1 := b[1:5] // array[low:high] 从low开始, high-low个元素
fmt.Println(s1)
c := []int{}
c = append(c, 1)
fmt.Println(c)
// 切片作为参数传递时为 饮用传递
// map[key] value
m1 := map[int]string{
1: "mike",
2: "yoyo",
3: "xxx", //结尾还必须得有这个逗号 0.0
}
for key, val := range m1 {
fmt.Println(key, val)
}
// map 修改
m1[1] = "ccc"
fmt.Println(m1)
// map 扩容
m1[4] = "dsa"
fmt.Println(m1)
// map 删除
delete(m1, 4)
fmt.Println(m1)
// map 也是引用传递
// 结构体
type Student struct {
id int
name string
}
var s Student
s.id = 1
s.name = "das"
fmt.Println(s)
}