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.本程序支持文件夹嵌套上传下载: ...
随机推荐
- Windows与Linux端口占用查询及处理
Windows下端口占用查询 输入命令:netstat -ano,列出所有端口的情况.在列表中我们观察被占用的端口,比如是49157,首先找到它. 查看被占用端口对应的PID,输入命令:netstat ...
- new 和 delete
new 和 delete 众所周知,C中的malloc和free是用来申请和释放内存的,相应的C++中也有对应的申请和释放内存的操作,即是new和delete,但是C++的new和delete比C中的 ...
- Windows添加用户和组命令
查看当前存在用户: net user 查看当前用户组: net localgroup 添加用户(以添加用户ls密码abcd1234为例): net user ls abcd1234 /add 添加用户 ...
- python 判断变量是否存在 防止报错
Python判断变量是否存在 方法一:使用try: ... except NameError: .... try: var except NameError: var_exists = False e ...
- LY.JAVA面向对象编程.内部类
2018-07-18 10:14:48 /* 内部类概述: 把类定义在其他类的内部,这个类就被称为内部类. 举例:在类A中定义了一个类B,类B就是内部类. 内部的访问特点: A:内部类可以直接访问外部 ...
- learning ddr mode reigsters
For application flexibility, various functions, features, and modes are programmable in four Mode Re ...
- 基于Redis+MySQL+MongoDB存储架构应用
摘 要: Redis+MySQL+MongoDB技术架构实现了本项目中大数据存储和实时云计算的需求.使用MongoDB切片的水平动态添加,可在不中断平台业务系统的同时保障扩容后的查询速度和云计算效能 ...
- caffe,Inception v2 Check failed: top_shape[j] == bottom[i]->shape(j)
使用Caffe 跑 Google 的Inception V2 对输入图片的shape有要求,某些shape输进去可能会报错. Inception model中有从conv和pooling层concat ...
- C++中重载(overload)、覆盖(override)与隐藏(oversee)
body, table{font-family: 微软雅黑; font-size: 10pt} table{border-collapse: collapse; border: solid gray; ...
- 通过eclipse创建项目
基于eclipse的Java文件:项目(project)<类(class)<方法(method),即方法method必须基于class, class必须基于project. 项目是程序的源 ...