![](https://img-blog.csdnimg.cn/20200807182522557.jpg?x-oss-process=image/resize,m_fixed,h_224,w_224)
Golang
Golang学习专栏
Crayon魚禾
这个作者很懒,什么都没留下…
展开
-
GO语言:slice切片
GO语言:切片 注意:在go语言中,切片属于引用类型,数组属于数值类型 var arr = [3]int{1, 2, 3} var slice = []int{1, 2, 3} temp1 := arr fmt.Printf("arr:%p temp1:%p\n", &arr, &temp1) temp2 := slice fmt.Printf("slice:%p temp2:%p\n", slice, temp2) arr:0xc00000a3e0 temp1:0xc0000原创 2020-08-06 21:55:59 · 237 阅读 · 0 评论 -
GO语言:string
GO语言:string len() // 求长度 len() 所得为字符串所占的字节数 length := len("Hello world") fmt.Println(length) // len == 12 go语言字符串使用utf-8编码 一个汉字占3个字节 length = len("我是魚禾") fmt.Println(length) 结果: 11 12 len()获取的是字符串所占字节数的大小,而不是字符串字符的数量 若要计算字符串字符数量,因先将字符串转换为[]rune切片原创 2020-08-06 18:01:46 · 212 阅读 · 0 评论 -
GO语言:const常量
GO语言:const常量 常量声明 单行常量声明,声明时必须指定值,且无法修改 const pi = 3.14 多行常量声明,若省略赋值,则默认与上一行值相同 const ( a = 100 b = 200 c // c = 200 d // d = 200 ) iota 常量计数器 ①iota只能在常量表达式中使用 ②遇到const关键字重置为0 const ( aa = iota // 0 bb // bb = iota 1 cc // cc = iota原创 2020-08-06 18:02:15 · 483 阅读 · 0 评论 -
GO语言:第一个go程序
GO语言:第一个go程序 package main import "fmt" //go中双引号表示字符串,单引号表示字符‘char’,类似C语言 func main() { fmt.Println("Hello world") } 编写以上go程序,通过一下命令运行程序 go run main.go //直接运行程序,类似于python中的解释器 go build //将go源代码文件直接编译成可执行文件 go build -o xxx.exe //可以通过-o选项来指定编译后的文件名 //编译结原创 2020-08-06 18:02:43 · 140 阅读 · 0 评论