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. Spring JdbcTemplate 查询出的Map,是如何产生大小写忽略的Key的?(转)

    原文地址:Spring JdbcTemplate 查询出的Map,是如何产生大小写忽略的Key的? 原始讨论组:用Spring JdbcTemplate 查询出的Map,是如何产生大小写忽略的Key的 ...

  2. zzw原创_LIKE与regexp_like中的_及转义符

    1.select table_name from user_tables  where table_name like 'MENU%';查出以下表MENUMENUGGG_131MENU_132MENU ...

  3. 一、持久层框架(Hibernate)

    一.Hibernate 使用JDBC做数据库相关功能开发会做很多重复性的工作,创建连接,关闭连接,把字段逐一映射到属性中等.Hibernate把这些进行封装起来,使得数据库访问变得轻松简单. 1.创建 ...

  4. 2015-09-28认识js1

             Javascript  一.特点 1. 区分大小写 2. 弱类型变量,只能用关键字“var" 3.注释 /*….*/ 二. 变量 1.变量通过关键字var声明. 2.var ...

  5. 在js中if条件为null/undefined/0/NaN/""表达式时,统统被解释为false,此外均为true

    Boolean 表达式 一个值为 true 或者 false 的表达式.如果需要,非 Boolean 表达式也可以被转换为 Boolean 值,但是要遵循下列规则: 所有的对象都被当作 true. 当 ...

  6. Intel daal数据预处理

    https://software.intel.com/en-us/daal-programming-guide-datasource-featureextraction-py # file: data ...

  7. 【HttpClient】一个http_post请求例子

    package httpclient.httpclient; import java.io.IOException; import org.apache.http.Header; import org ...

  8. 双向链表--首页大小不一卡片排序 --- react --- js

    1.4中类型(grid_type)的卡片:1:大方块:2:竖长块:3:横长块:4:小方块 var order = 0; // 创建链表 function List(head) { this.head ...

  9. 从mysql读取数据写入mongo

    # coding:utf-8 # Created by qinlin.liu at 2017/3/14 import pymysql import datetime #pymongo说明文档  : h ...

  10. xml文档的读取

    #! /usr/bin/env python3 # -*- coding:utf-8 -*- import xml.dom.minidom  #该模块被用来处理xml文件 #打开xml文档 dom=x ...