当前位置:网站首页>Go language self-study series | golang structure pointer
Go language self-study series | golang structure pointer
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
Structure pointer is the same as ordinary variable pointer , Let me first review the pointers to ordinary variables , for example :
package main
import "fmt"
func main() {
var name string
name = "tom"
// p_name Pointer types
var p_name *string
// &name take name Address
p_name = &name
fmt.Printf("name: %v\n", name)
// Output pointer address
fmt.Printf("p_name: %v\n", p_name)
// Output the content value pointed to by the pointer
fmt.Printf("*p_name: %v\n", *p_name)
}
Running results
[Running] go run "d:\SynologyDrive\ software development \go\golang Introduction to project practice \goproject\360duote.com\pro01\test.go"
name: tom
p_name: 0xc000050230
*p_name: tom
go Structure pointer
example
package main
import "fmt"
func main() {
type Person struct {
id int
name string
}
var tom = Person{1, "tom"}
var p_person *Person
p_person = &tom
fmt.Printf("tom: %v\n", tom)
fmt.Printf("p_person: %p\n", p_person)
fmt.Printf("*p_person: %v\n", *p_person)
}
Running results
[Running] go run "d:\SynologyDrive\ software development \go\golang Introduction to project practice \goproject\360duote.com\pro01\test.go"
tom: {1 tom}
p_person: 0xc000004078
*p_person: {1 tom}
Use new Keyword to create a structure pointer
We can also use new Key to instantiate the structure , What we get is the address of the structure , for example :
package main
import "fmt"
func main() {
type Person struct {
id int
name string
}
var p_person = new(Person)
fmt.Printf("p_person: %T\n", p_person)
}
Running results
[Running] go run "d:\SynologyDrive\ software development \go\golang Introduction to project practice \goproject\360duote.com\pro01\test.go"
p_person: *main.Person
From run results , We found that p_person Is pointer type
Access structure pointer members
Access structure pointer members , Point operators are also used (.), for example :
package main
import "fmt"
func main() {
type Person struct {
id int
name string
}
var p_person = new(Person)
fmt.Printf("p_person: %T\n", p_person)
p_person.id = 1
p_person.name = "tom"
fmt.Printf("*p_person: %v\n", *p_person)
}
Running results
[Running] go run "d:\SynologyDrive\ software development \go\golang Introduction to project practice \goproject\360duote.com\pro01\test.go"
p_person: *main.Person
*p_person: {1 tom}
版权声明
本文为[COCOgsta]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230822135868.html
边栏推荐
- Consensus Token:web3.0生态流量的超级入口
- 增强现实技术是什么?能用在哪些地方?
- 洋桃电子STM32物联网入门30步笔记三、新建CubeIDE工程和设置讲解
- STM32使用HAL库,整体结构和函数原理介绍
- Multi view depth estimation by fusing single view depth probability with multi view geometry
- 1099 establish binary search tree (30 points)
- swagger文档导出自定义v2/api-docs拦截
- 经典题目刷一刷
- Learn SQL injection in sqli liabs (Level 11 ~ level 20)
- Notes d'apprentissage oneflow: de functor à opexprinterpreter
猜你喜欢

引用传递1

Share the office and improve the settled experience

Consensus Token:web3.0生态流量的超级入口

Star Trek's strong attack opens the dream linkage between metacosmic virtual reality

洋桃电子STM32物联网入门30步笔记三、CubeMX图形化编程、设置开发板上的IO口

Harbor企业级镜像管理系统实战

PLC point table (register address and point table definition) cracking detection scheme -- convenient for industrial Internet data acquisition

汇编语言与逆向工程 栈溢出漏洞逆向分析实验报告

在sqli-liabs学习SQL注入之旅(第十一关~第二十关)

深度学习框架中的自动微分及高阶导数
随机推荐
增强现实技术是什么?能用在哪些地方?
论文阅读《Multi-View Depth Estimation by Fusing Single-View Depth Probability with Multi-View Geometry》
Go语言自学系列 | golang结构体作为函数参数
STM32F103ZET6【标准库函数开发】----库函数介绍
STM32 uses Hal library. The overall structure and function principle are introduced
okcc呼叫中心外呼系统智能系统需要用多大的盘存录音?
Star Trek强势来袭 开启元宇宙虚拟与现实的梦幻联动
PCTP考试经验分享
Failed to prepare device for development
洋桃電子STM32物聯網入門30步筆記一、HAL庫和標准庫的區別
【58】最后一个单词的长度【LeetCode】
Get the absolute path of the class according to the bytecode
DJ音乐管理软件Pioneer DJ rekordbox
引用传递1
还原二叉树 (25 分)
洋桃电子STM32物联网入门30步笔记三、CubeMX图形化编程、设置开发板上的IO口
2022-04-22 openebs cloud native storage
政务中台研究目的建设目标,建设意义,技术创新点,技术效果
Automatic differentiation and higher order derivative in deep learning framework
How much inventory recording does the intelligent system of external call system of okcc call center need?