go 指针

一、什么是指针

 

二、指针操作

  1、如何声明指针类型,   *int,在类型前面加个*号

    *号是指针类型,取值(把内存地址值变成值)。&号(取址符)是读取值内存地址。

package main

import "fmt"

func main(){
	s := "good bye"
	var p *string = &s
	*p = "ciao"
	fmt.Printf("Here is the pointer p: %p\n", p) //Here is the pointer p: 0x10b840f0
	fmt.Printf("Here is the string *p: %s\n", *p)//Here is the string *p: ciao
	fmt.Printf("Here is the string  s: %s\n", s )//Here is the string  s: ciao
}

 s是赋值。

 &s是提取内存地址。*p是值。*string是内存地址。

内存示意图如下:

 

 

转载于:https://www.cnblogs.com/liubiaos/p/9362297.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值