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. ECharts 报表事件联动系列一:刷新页面

    本示例实现了以下功能: 1.点击刷新按钮,仅刷新柱状图,而不是整个页面 2.点击柱状内容刷新柱状图,并更新title 3.点击X轴,Y轴更新title,并弹出alert. 源码代码如下: <!D ...

  2. Pick-up sticks

    Pick-up sticks Stan has n sticks of various length. He throws them one at a time on the floor in a r ...

  3. Linux下切换使用两个版本的JDK

    Linux下切换使用两个版本的JDK 我这里原来已经配置好过一个1.7版本的jdk. 输出命令: java -version [root@hu-hadoop1 sbin]# java -version ...

  4. group by 错误

    出现错误: which is not functionally dependent on columns in GROUP BY clause; this is incompatible with s ...

  5. for循环的字节码

    源代码: public class Wizard { private int age; private void forCycle() { for (int i = 0; i < 10; i++ ...

  6. Linux登录超时自动退出处理办法

    出于安全方面的考虑,机器常要求配置一个登录时间期限,当闲置超过这一期限就自动退出:但在某些场合我们需要时不时地就使用机器,如果每次都要重新ssh登录那是非常麻烦的 方法一:让当前会话一直处于工作状态 ...

  7. [转]每天一个linux命令(44):top命令

    top命令是Linux下常用的性能分析工具,能够实时显示系统中各个进程的资源占用状况,类似于Windows的任务管理器.下面详细介绍它的使用方法.top是一个动态显示过程,即可以通过用户按键来不断刷新 ...

  8. read later

       https://groups.google.com/forum/#!msg/pylearn-users/FYtpaQKoC4c/ubitO_JUC1kJ           网上论坛 发布回复 ...

  9. Zookeeper的实际应用

    Zookeeper是hadoop的一个子项目,虽然源自hadoop,但是我发现zookeeper脱离hadoop的范畴开发分布式框架的运用越来越多.今天我想谈谈zookeeper,本文不谈如何使用zo ...

  10. CAD绘制室外台阶步骤5.4

    1.在CAD的平面上用PL命令绘制台阶,如图: 绘制好了之后.进入三维模型,“工具""移位”选择台阶,回车,"Z"回车,输入数值“-450”如图 2.输入命令“ ...