当前位置:网站首页>Go语言浅拷贝与深拷贝
Go语言浅拷贝与深拷贝
2022-06-26 07:56:00 【mq-shao】
- 深拷贝:拷贝数据,两变量的地址不同,拷贝结束后两个变量的操作互不影响
- 浅拷贝:拷贝地址,拷贝结束后两个变量的操作互相影响,一个变量的修改会影响另一个变量
package main
import (
"fmt"
)
func main() {
var src []int
src = []int{1, 2, 3}
fmt.Println("初始值src : ", src)
fmt.Println("---------------------")
des1 := src
des2 := make([]int, len(src))
copy(des2, src)
fmt.Println("浅拷贝des1: ", des1)
fmt.Println("深拷贝des2: ", des2)
fmt.Println("---------------------")
src[1] = 0
fmt.Println("修改src : ", src)
fmt.Println("des1: ", des1)
fmt.Println("des2: ", des2)
}
边栏推荐
- Leetcode topic [array] -11- containers with the most rainwater
- [UVM basics] TLM common data receiving and sending and data receiving examples
- Exit of shell internal value command
- 花指令wp
- Chapter VII (structure)
- Pic 10B parsing
- ASP. Net and Net framework and C #
- Seven important reasons for responsive Web Design
- Yyds dry inventory kubernetes easy service discovery and load balancing (11)
- Redis(5)----浅谈压缩列表
猜你喜欢

What is Wi Fi 6 (802.11ax)? Why is Wi Fi 6 important?

Livevideostackcon | evolution of streaming media distribution for online education business

buuresevewp

buuresevewp

Win11 open folder Caton solution summary

ReW_p

Chapter 9 (using classes and objects)

Solution to the problem of multi application routing using thinkphp6.0

Wifi-802.11 2.4G band 5g band channel frequency allocation table

Color code
随机推荐
Wifi-802.11 2.4G band 5g band channel frequency allocation table
buuresevewp
JS Date object
Google Earth engine (GEE) 02 basic knowledge and learning resources
Jemter 压力测试 -可视化工具-【使用篇】
手机开户哪个证券公司佣金最低?网上开户是否安全么?
Color code
Record the dependent installation problems encountered in building the web assets when developing pgadmin
Children play games (greed, prefix and) - Niuke winter vacation training camp
[UVM basics] TLM common data receiving and sending and data receiving examples
What is the difference between bone conduction earphones and ordinary earphones? Advantages of bone conduction earphones
PyTorch-12 GAN、WGAN
buuresevewp
Arrangement and insertion structure
ASP. Net and Net framework and C #
B站增量数据湖探索与实践
Hand drawn style chart library chart Implementation principle of xkcd
OSPF design principles, commands take H3C as an example
Comparison version number [leetcode]
Redis (4) -- Talking about integer set