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

相关推荐
Moment9 小时前
Vibe Coding 时代,到底该选什么样的工具来提升效率❓❓❓
前端·后端·github
Victor3569 小时前
MongoDB(27)什么是文本索引?
后端
可夫小子10 小时前
OpenClaw基础-3-telegram机器人配置与加入群聊
后端
IT_陈寒10 小时前
SpringBoot性能飙升200%?这5个隐藏配置你必须知道!
前端·人工智能·后端
aiopencode11 小时前
使用 Ipa Guard 命令行版本将 IPA 混淆接入自动化流程
后端·ios
掘金者阿豪11 小时前
Kavita+cpolar 打造随身数字书房,让资源不再混乱,通勤 、出差都能随心读。
后端
心之语歌12 小时前
Spring Security api接口 认证放行
后端
用户83562907805112 小时前
Python 实现 PPT 转 HTML
后端·python
0xDevNull12 小时前
MySQL索引进阶用法
后端·mysql
舒一笑12 小时前
程序员效率神器:一文掌握 tmux(服务器开发必备工具)
运维·后端·程序员