当前位置:网站首页>Go language self-study series | initialization of golang structure
Go language self-study series | initialization of golang structure
2022-04-23 08:50:00 【COCOgsta】
Video source :B standing 《golang Introduction to project practice [2021 newest Go Language course , There is no nonsense , Dry only ! Ongoing update ...]》
Organize the teacher's course content and test notes while studying , And share it with you , Infringement is deleted , Thank you for your support !
Attach summary sticker :Go Language self-study series | Summary _COCOgsta The blog of -CSDN Blog
Uninitialized structure , Members are all zero values int 0 flow 0.0 bool false string nil nil
example
package main
import "fmt"
func main() {
type Person struct {
id, age int
name, email string
}
var tom Person
fmt.Printf("tom: %v\n", tom)
}
Running results
[Running] go run "d:\SynologyDrive\ software development \go\golang Introduction to project practice \goproject\360duote.com\pro01\test.go"
tom: {0 0 }
Initialize the structure with key value pairs
example
package main
import "fmt"
func main() {
type Person struct {
id, age int
name, email string
}
kite := Person{
id: 1,
name: "kite",
age: 20,
email: "[email protected]",
}
fmt.Printf("kite: %v\n", kite)
}
Running results
[Running] go run "d:\SynologyDrive\ software development \go\golang Introduction to project practice \goproject\360duote.com\pro01\test.go"
kite: {1 20 kite [email protected]}
Initialize with a list of values
example
package main
import "fmt"
func main() {
type Person struct {
id, age int
name, email string
}
kite := Person{
1,
20,
"kite",
"[email protected]",
}
fmt.Printf("kite: %v\n", kite)
}
Running results
[Running] go run "d:\SynologyDrive\ software development \go\golang Introduction to project practice \goproject\360duote.com\pro01\test.go"
kite: {1 20 kite [email protected]}
Be careful :
- All fields of the structure must be initialized .
- The initial values must be filled in the same order as the fields are declared in the structure .
- This method cannot be mixed with the key initialization method .
Initialization of some members
Unused members , It can be done without initialization
package main
import "fmt"
func main() {
type Person struct {
id, age int
name, email string
}
kite := Person{
id: 1,
name: "kite",
}
fmt.Printf("kite: %v\n", kite)
}
Running results
[Running] go run "d:\SynologyDrive\ software development \go\golang Introduction to project practice \goproject\360duote.com\pro01\test.go"
kite: {1 0 kite }
版权声明
本文为[COCOgsta]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230822135909.html
边栏推荐
- Get the absolute path of the class according to the bytecode
- 洋桃电子STM32物联网入门30步笔记三、新建CubeIDE工程和设置讲解
- PLC point table (register address and point table definition) cracking detection scheme -- convenient for industrial Internet data acquisition
- Flink同时读取mysql与pgsql程序会卡住且没有日志
- 1099 establish binary search tree (30 points)
- 关于cin,scanf和getline,getchar,cin.getline的混合使用
- Go语言自学系列 | golang结构体作为函数参数
- L2-3 romantic silhouette (25 points)
- uni-app和微信小程序中的getCurrentPages()
- 2021 Li Hongyi's adaptive learning rate of machine learning
猜你喜欢
随机推荐
'bully' Oracle enlarged its move again, and major enterprises deleted JDK overnight...
Learn SQL injection in sqli liabs (Level 11 ~ level 20)
STM32 uses Hal library. The overall structure and function principle are introduced
2022-04-22 openebs cloud native storage
LINQ Learning Series ----- 1.4 anonymous objects
Virtual online exhibition - Online VR exhibition hall realizes 24h immersive exhibition viewing
Bk3633 specification
IDEA导入commons-logging-1.2.jar包
洋桃电子STM32物联网入门30步笔记三、新建CubeIDE工程和设置讲解
php基于哈希算法出现的强弱比较漏洞
正点原子携手OneOS直播 OneOS系统教程全面上线
微信:获取单个标签所有人
Restore binary tree (25 points)
tsdf +mvs
洋桃电子STM32物联网入门30步笔记三、CubeMX图形化编程、设置开发板上的IO口
Yangtao electronic STM32 Internet of things entry 30 step notes IV. engineering compilation and download
【58】最后一个单词的长度【LeetCode】
Study notes of deep learning (8)
OneFlow学习笔记:从Functor到OpExprInterpreter
PCTP考试经验分享









