go syntax

Variable

Zero value concept

Every single value we create must be initialized. If we don't specify it, it will be set to
the zero value. The entire allocation of memory, we reset that bit to 0.
1 - Boolean false
2 - Integer 0
3 - Floating Point 0
4 - Complex 0i
5 - String "" (empty string)
6 - Pointer nil

Strings are a series of uint8 types.
A string is a two word data structure: first word represents a pointer to a backing array, thesecond word represents its length.
If it is a zero value then the first word is nil, the second word is 0.

var is the only guarantee to initialize a zero value for a type

Conversion vs casting

Go doesn't have casting, but conversion.
Instead of telling a compiler to pretend to have some more bytes, we have to allocate more memory.
Specify type and perform a conversion.

aaa := int32(10)
go reference type

Reference types: slice, map, channel, interface, function.
Zero value of a reference type is nil.

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容