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
", p) //Here is the pointer p: 0x10b840f0
	fmt.Printf("Here is the string *p: %s
", *p)//Here is the string *p: ciao
	fmt.Printf("Here is the string  s: %s
", s )//Here is the string  s: ciao
}

 s是赋值。

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

内存示意图如下:

 

原文地址:https://www.cnblogs.com/liubiaos/p/9362297.html