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是内存地址。

内存示意图如下:

 

 

posted @ 2018-07-24 20:07  liubiaos  阅读(144)  评论(0编辑  收藏  举报