Go parameter passing
package main import (
"fmt"
) func main() {
fmt.Println("Hello, playground") var str string = "1241341"
fmt.Println(&str)
fmt.Println(MyString(str)) m := map[string]string {"A": "A"}
fmt.Printf("m before %p\n", &m)
modify(m)
fmt.Println("m val: ", m["A"])
} func MyString(v string) *string {
return &v
} func modify(m map[string]string) {
fmt.Printf("m after %p\n", &m)
m["A"] = "B"
}
Hello, playground
0x1040c130
0x1040c138
m before 0x1040c140
m after 0x1040c148
m val: B 结论:
1)golang参数传递都是值传递,即会复制一份副本。
2)值传递为何会改变了map?
sclice、map、chan、interface和function都属于引用类型,引用类型复传参时复制的是一份指针,其指向底层数据结构相同。因此可改变之。 update:
闭包,传递的是引用。其实不用记,想想就应该这样
Go parameter passing的更多相关文章
- More about Parameter Passing in Python(Mainly about list)
我之前写了一篇关于Python参数传递(http://www.cnblogs.com/lxw0109/p/python_parameter_passing.html)的博客, 写完之后,我发现我在使用 ...
- Parameter Passing / Request Parameters in JSF 2.0 (转)
This Blog is a compilation of various methods of passing Request Parameters in JSF (2.0 +) (1) f:vi ...
- Python Parameter Passing Note
我刚刚开始学习Python, Python中的参数传递总是让我很困惑.我写了4个简单的Demo,帮助我理解Python的参数传递,希望对大家都能有所帮助. 0: def change(x): x = ...
- [转]Passing Managed Structures With Strings To Unmanaged Code Part 3
1. Introduction. 1.1 In part 1 of this series of blogs we studied how to pass a managed structure (w ...
- [转]Passing Managed Structures With Strings To Unmanaged Code Part 2
1. Introduction. 1.1 In part 1 of this series of blogs we studied how to pass a managed structure (w ...
- [python] File path and system path
1. get files in the current directory with the assum that the directory is like this: a .py |----dat ...
- va_list深究
va_list深究 2011-04-21 21:06:11| 分类: C/C++|字号 订阅 VA函数(variable argument function),参数个数可变函数,又称可变参数 ...
- A Simple C++ Template Class that Matches a String to a Wildcard Pattern
A recently implemented enhanced wildcard string matcher, features of which including, Supporting wil ...
- FTP客户端上传下载Demo实现
1.第一次感觉MS也有这么难用的MFC类: 2.CFtpFileFind类只能实例化一个,多个实例同时查找会出错(因此下载时不能递归),采用队列存储目录再依次下载: 3.本程序支持文件夹嵌套上传下载: ...
随机推荐
- Directory /home/hdfs/name is in an inconsistent state: storage directory does not exist or is not a
2018-06-11 17:50:36,896 WARN org.apache.hadoop.hdfs.server.namenode.FSNamesystem: Encountered except ...
- CP-ABE的使用
参考: http://acsc.cs.utexas.edu/cpabe/tutorial.html http://acsc.cs.utexas.edu/cpabe/ 事先先配置好cp-abe:http ...
- Python学习之路【第二篇】-pyc简介、Python常用的数据类型及其用法和常用运算符
1.pyc简介 python程序在运行时也有编译过程,编译后会产生.pyc文件.这是一种由python虚拟机执行的二进制文件(字节码),用于保存内存中PyCodeObject,以便加快程序的加载运行. ...
- xmanager运行报错:bash: /usr/bin/xterm: No such file or directory
1.原因 xterm没有安装,解决办法是下载然后安装即可. 如果机器可以用yum,则直接使用yum安装xterm即可: yum install -y xterm 如果没有网络,则在某台操作系统大版本相 ...
- 牛客网 PAT 算法历年真题 1008 : 锤子剪刀布 (20)
锤子剪刀布 (20) 时间限制 1000 ms 内存限制 32768 KB 代码长度限制 100 KB 判断程序 Standard (来自 小小) 题目描述 大家应该都会玩“锤子剪刀布”的游戏:现给出 ...
- 微信小程序 带参调用后台接口 循环渲染页面 wx.request wx:for
test.js 文件里的onLoad function getarticles(p,order,mythis) { wx.request({ url: 'https://ganggouo.cn/ind ...
- js实现页面与页面之间传值的几种方法优劣
1. cookie 传值, 缺点: cookie储存是需要服务器支持的,本地直接运行静态文件是实现不了的 <script> //添加 cookie function cp_add_cook ...
- Mac下安装和配置Maven
1.下载Maven 官网:http://maven.apache.org/download.cgi 下载版本:apache-maven-3.5.3-bin.tar.gz 2.配置环境变量 打开term ...
- 【框架】用excel管理测试用例需要的参数数据(二)
一.总体思路 以类为excel名,测试方法名为sheet名,建立excel文件.用jxl包里的方法去读取excel文件里的内容,然后用testng里的dataprovider,将数据传递给测试用例 二 ...
- Win10系列:JavaScript 控件的使用
向页面中添加的控件可分为两种类型:标准的HTML控件和WinJS库控件.其中标准的HTML控件是指HTML标准中定义的基本控件,如按钮和复选框:WinJS库控件是为开发基于JavaScript 的Wi ...