Go 自学:pointer指针

以下代码中,我们建立指针ptr指向myNumber的地址。

*ptr代表指针指向的值。

我们改变指针*ptr,可以改变被指向的变量的值。

go 复制代码
package main

import "fmt"

func main() {
	myNumber := 23

	var ptr = &myNumber

	fmt.Println("Value of the address is ", ptr)
	fmt.Println("Value of actual pointer is ", *ptr)

	*ptr = *ptr + 2
	fmt.Println("New value is: ", myNumber)
}

输出为:

Value of the address is 0xc00000a0a8

Value of actual pointer is 23

New value is: 25

相关推荐
无尽的沉默12 分钟前
SpringBoot整合MyBatis-plus
spring boot·后端·mybatis
浅念-31 分钟前
C++ :类和对象(4)
c语言·开发语言·c++·经验分享·笔记·学习·算法
lly20240636 分钟前
Docker 安装 Python
开发语言
道法自然|~44 分钟前
BugkuCTF栅栏密码解题记录(原理+C语言实现)
c语言·开发语言
CircleMouse1 小时前
springboot项目中使用Java 8的日期时间API
java·开发语言·spring boot·后端·spring
UrbanJazzerati2 小时前
Python 导包、分包完全教程
后端·面试
前端达人2 小时前
被JavaScript忽视的Web Animations API:为什么说它是前端动画的真正未来?
开发语言·前端·javascript·ecmascript
米羊1212 小时前
风险评估文档记录
开发语言·网络·php
摘星编程2 小时前
解锁Agent智能体的未来:五大实战策略彻底革新人机协作模式
java·开发语言