当前位置:网站首页>Go language self-study series | golang pointer
Go language self-study series | golang pointer
2022-04-21 22:52: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
Go The function parameters in the language are all value copies , When we want to modify a variable , We can create a pointer to the address of the variable . Passing data using pointers , Without copying data .
Type pointers cannot be offset and operated .
Go Pointer operation in language is very simple , Just remember two symbols :&( Address fetch ) and *( According to the address )
Pointer address and pointer type
Each variable has an address at run time , This address represents the location of the variable in memory .Go Used in language & The character is placed in front of the variable to address the variable .Go Value types in languages (int、float、bool、string、array、struct) All have corresponding pointer types , Such as :*int、*int64、*string etc. .
Pointer Syntax
A pointer variable points to the memory address of a value .( That is, after we declare a pointer , It can be assigned as a variable , Put the memory address of a value into the pointer .)
Similar to variables and constants , You need to declare pointers before using them . The format of the pointer declaration is as follows :
var var_name *var-type
var-type: Is pointer type
var_name: Is the pointer variable name
*: Used to specify that the variable is used as a pointer .
Pointer declaration example
var ip *int /* Directed integer */
var fp *float32 /* Point to floating point */
Pointer usage example
package main
import "fmt"
func main() {
var a int = 20 /* Declare the actual variable */
var ip *int /* Declare pointer variables */
ip = &a /* Storage address of pointer variable */
fmt.Printf("a The address of the variable is : %x\n", &a)
/* Storage address of pointer variable */
fmt.Printf("ip Pointer address of variable storage : %x\n", ip)
/* Use a pointer to access */
fmt.Printf("*ip The value of the variable : %d\n", *ip)
}
Running results
[Running] go run "d:\SynologyDrive\ software development \go\golang Introduction to project practice \goproject\360duote.com\pro01\test.go"
a The address of the variable is : c000014098
ip Pointer address of variable storage : c000014098
*ip The value of the variable : 20
版权声明
本文为[COCOgsta]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204212034375999.html
边栏推荐
- [MQ] starting from scratch to realize mq-01-start of producers and consumers
- 主流app开发工具,你头秃都没想到还能这样吧
- TensorFlow 2.8 安装
- Review questions and answers of building materials and structures in 2022 first-class registered architect examination
- MySQL read / write separation
- [summary of some tips and shortcut keys in MATLAB]
- Reproduce the pathways language model using colossal AI
- [matlab] matlab drawing operation skills
- GO111MODULE=on go mod init错误(go: cannot determine module path for source directory)
- Black box test - data reading and output mode
猜你喜欢

Concept and working principle of image acquisition card
![[pytorch] common functions](/img/ff/db57ec07bb3b2fb14ea1e2424cea0a.jpg)
[pytorch] common functions

1957年高考数学题

When the color contrast of beix3 is good, the color of the new version 3.1 is close to the original image

Oracle database 22c insight:_ kgl_ Large_ heap_ assert_ Threshold automatic and manual adjustment

Apache Flink series - ④ stateful functions

Opencv -- geometric transformation

2022 Intermediate Accounting Title Financial Management exercises and answers
![P1053 [NOIP2005 提高组] 篝火晚会](/img/b5/f95a8d4976edcd03c5eb2351dd1aa2.png)
P1053 [NOIP2005 提高组] 篝火晚会

1. MySQL workbench 8.0 installation
随机推荐
Deep understanding of MySQL locks
当贝X3色彩对比度好不好,新3.1版本色彩接近原图
Cleaning robot - infrared down looking sensor to detect whether there is a sudden change in ground distance
【FPGA的基础学习-------OV7725摄像头模块】
L1-059 ringing stupid bell (20 minutes)
YARN线上动态资源调优
What is the core design of Dadi's performance advantage in the cache hit scenario?
Database exercise
VOS6.0安装及源码命令
L1-062 lucky lottery (15 points)
深入理解mysql各种锁
L1-063 fish or meat (10 points)
2022-04-21: given a blacklist containing non repeating integers in [0, n), write a function to return a random integer not in the blacklist from [0, n)
Rvb2601 startup process
Concept and working principle of image acquisition card
2022 intermediate accounting title examination economic law practice questions and answers
Languages supported by markdown code blocks
P1053 [NOIP2005 提高组] 篝火晚会
One plus two earphone products: charge for 10 minutes and listen to music for 20 hours
P1027 [noip2001 improvement group] car's travel route (the shortest path in the diagram)