当前位置:网站首页>golang复习总结
golang复习总结
2022-07-25 14:59:00 【kentrl】
golang的变量分为:值类型,指针类型,引用类型。
1. 引用类型变量:slice,map,channel 三种2. 其他都是值类型变量
变量的默认值:
- 指针类型的,零值都是nil
- 值类型的变量,零值是其所在类型的零值
- map(
引用类型)的零值是nil,- int32类型的零值是0
- string类型的零值是""
- bool类型的零值是false
- 符合结构struct类型的零值是其每个成员的零值的组合
struct的零值是Student1{0, “”}
struct类型和nil是两种不同的类型,不能比较。
1:基本类型
负整型:包括int,int8,int16,int32,int64
正整型:包括uint,uint8,uint32,uint64,
byte 存放字符
rune 代表一个 utf-8 字符
uintptr 存放指针
浮点型:包括float32,float64
复数类型:包括complex64,complex128
字符串类型:string
布尔型:bool
int类型的大小为 8 字节
int8类型大小为 1 字节
int16类型大小为 2 字节
int32类型大小为 4 字节
int64类型大小为 8 字节
2:复合类型
数组
struct结构体
3:引用类型
slice
map
channel
pointer or 引用类型
4:接口类型
io.Reader, io.Writer,error等
类型比较的总结:
- 复合类型,只有每个元素(成员)可比较,而且类型和值都相等时,两个复合元素才相等
- slice,map不可比较,但是可以用reflect或者cmp包来比较
- func作为golnag的一等公民,也是一个类型,也不能比较。
- 引用类型的比较是看指向的是不是同一个变量
- 类型再定义(type A string)不可比较,是两种不同的类型
- 类型别名(type A = string)可比较,是同一种类型。
边栏推荐
- Leetcode combination sum + pruning
- Syntax summary of easygui
- API health status self inspection
- Vs2010添加wap移动窗体模板
- QT connect, signal, slot and lambda comparison
- Several methods of spark parameter configuration
- Niuke multi school E G J L
- CMake指定OpenCV版本
- Login of MySQL [database system]
- Client error: invalid param endpoint is blank
猜你喜欢

51 single chip microcomputer learning notes (1)

Unable to start web server when Nacos starts

As methods for viewing and excluding dependencies

Gameframework making games (II) making UI interface

Deng Qinglin, a technical expert of Alibaba cloud: Best Practices for disaster recovery and remote multi activity across availability zones on cloud

I2C设备驱动程序的层次结构
![[Nacos] what does nacosclient do during service registration](/img/76/3c2e8f9ba19e36d9581f34fda65923.png)
[Nacos] what does nacosclient do during service registration

"How to use" decorator mode

Browser based split screen reading

41 图片背景综合-五彩导航图
随机推荐
Educational codeforces round 132 (rated for Div. 2) C, d+ac automata
[thread knowledge points] - spin lock
SSH服务器拒绝了密码
河源市区推出消防安全主题奶茶 助推夏季火灾防控
Deng Qinglin, a technical expert of Alibaba cloud: Best Practices for disaster recovery and remote multi activity across availability zones on cloud
MySQL 45 talks about | 06 global locks and table locks: Why are there so many obstacles to adding a field to a table?
PHP implements non blocking (concurrent) request mode through native curl
QT connect, signal, slot and lambda comparison
Gson and fastjson
6线SPI传输模式探索
[C topic] force buckle 876. Intermediate node of linked list
Awk from entry to earth (24) extract the IP of the instruction network card
Kibana operation es
35 quick format code
Examples of bio, NiO, AIO
@Scheduled source code analysis
二维数组赋初值你会几种方法?
AS查看依赖关系和排除依赖关系的办法
43 盒子模型
45padding won't open the box