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的更多相关文章

  1. More about Parameter Passing in Python(Mainly about list)

    我之前写了一篇关于Python参数传递(http://www.cnblogs.com/lxw0109/p/python_parameter_passing.html)的博客, 写完之后,我发现我在使用 ...

  2. 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 ...

  3. Python Parameter Passing Note

    我刚刚开始学习Python, Python中的参数传递总是让我很困惑.我写了4个简单的Demo,帮助我理解Python的参数传递,希望对大家都能有所帮助. 0: def change(x): x = ...

  4. [转]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 ...

  5. [转]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 ...

  6. [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 ...

  7. va_list深究

    va_list深究 2011-04-21 21:06:11|  分类: C/C++|字号 订阅     VA函数(variable argument function),参数个数可变函数,又称可变参数 ...

  8. 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 ...

  9. FTP客户端上传下载Demo实现

    1.第一次感觉MS也有这么难用的MFC类: 2.CFtpFileFind类只能实例化一个,多个实例同时查找会出错(因此下载时不能递归),采用队列存储目录再依次下载: 3.本程序支持文件夹嵌套上传下载: ...

随机推荐

  1. QT和JS的互相调用例子

    转自: http://blog.163.com/qimo601@126/blog/static/15822093201682185819623/ Qt 4.8.4 感谢原作者,我只转载. 看看作者如何 ...

  2. 撤销commit

    如果不小心commit了一个不需要commit的文件,可以对其进行撤销. 先使用git log 查看 commit日志 commit 422bc088a7d6c5429f1d0760d008d86c5 ...

  3. EXCEL词典(xllex.dll)文件丢失或损坏解决方法

    EXCEL词典(xllex.dll)文件丢失或损坏解决方法     1● 问题   2● 解决 fail 3● 方法2   regsvr32 xllex.dll     4● 方法3 启动server ...

  4. 微信PC客户端无法发送图片,怎么解决?

    今天登陆电脑的微信客户端,无法发送截图图片,该怎么办? 解决方法 1.在任务栏找到程序,右键找到设置

  5. EtherCAT(扒自百度百科)

    EtherCAT(以太网控制自动化技术)是一个开放架构,以以太网为基础的现场总线系统,其名称的CAT为控制自动化技术(Control Automation Technology)字首的缩写.Ether ...

  6. Daily record-June

    June201. Dear, wake up! Seven o'clock now, it's time to get up. Wash your face and to have breakfast ...

  7. .NET接入UnionPay银联支付(一)手机wap支付

    最近呢,比较忙,公司在接入银联全渠道支付,博主接手的wap支付,发表一下博主在接入的时候遇到的坑和注意事项,方便大家学习接入,爬坑的路上更顺利一点~ 开发步骤 1. 以表单的方式组装要发送给银联全渠道 ...

  8. Object value iterator:值迭代器

    // ES5 // 对于数组,使用标准的 for 循环,其实这种方式并不是在遍历值,而是遍历下标来指向值!ES5中增加了一些数组迭代器:forEach.every.some // forEach:遍历 ...

  9. [POJ3416]Crossing

    Problem 给你n个点,m个询问,每个询问有x, y 问以(x,y)为原点建立的平面直角坐标系分割的第一象限和第三象限的点数和减去第二象限和第四象限的点数和 Solution 用2个树状数组维护一 ...

  10. 【转】caffe数据层及参数

    原文: 要运行caffe,需要先创建一个模型(model),如比较常用的Lenet,Alex等, 而一个模型由多个层(layer)构成,每一层又由许多参数组成.所有的参数都定义在caffe.proto ...